Computer Applications
Give the output of the following string functions:
"DEDICATE".compareTo("DEVOTE")
Java
Java String Handling
ICSE 2018
92 Likes
Answer
-18
Working
"DEDICATE" and "DEVOTE" differ at the third character with 'D' and 'V', respectively. So, output of compareTo()
method will be ASCII Code of 'D' - ASCII Code of 'V' ⇒ 68 - 86 ⇒ -18.
Answered By
54 Likes
Related Questions
Consider the following String array and give the output
String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"}; System.out.println(arr[0].length() > arr[3].length()); System.out.print(arr[4].substring(0,3));
Give the output of the following statements:
String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
System.out.println(x[1]);
Give the output of the following string functions:
"ACHIEVEMENT".replace('E', 'A')Give the output of the following statements:
String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
System.out.println(x[3].length());