Computer Applications
The output of the java statement "SOLDIER".compareTo("SOLUTE"); is
- -4
- -17
- 17
- 0
Java String Handling
1 Like
Answer
-17
Reason — The compareTo() method in Java compares two strings lexicographically using the Unicode values.
Let's compare "SOLDIER" and "SOLUTE":
- The first three letters S, O, L are the same in both strings.
- The 4th letter in "SOLDIER" is 'D' and in "SOLUTE" it is 'U'.
- Unicode of 'D' = 68, Unicode of 'U' = 85.
- 68 − 85 = -17
So, the output is -17.
Answered By
3 Likes
Related Questions
Choose the statement which is equivalent to the given:
if(a>b) System.out.println("Honest"); else System.out.println("Sincere");a>b? System.out.println("Honest"):System.out.println("Sincere");System.out.println(a>b? "Honest":"Sincere");a>b? "Honest": "Sincere";a>b: "Honest"? "Sincere";
The two Java statement are used to check for the equality of the strings "COP" and "cop" are as follows:
"COP".equals("cop") "COP".equalsIgnoreCase("cop")The output of the above statements is:
- false, true
- true, false
- false, false
- true, true
Arrange the following in the descending order of number of bytes occupied.
(i) char x[20]
(ii) int a[4][2]
(iii) double b[6]- (iii), (ii), (i)
- (iii), (i), (ii)
- (ii), (iii), (i)
- (i), (ii), (iii)
Sam performs bubble sort on the following array to organise the elements in ascending order:
{5, 1, 2, 3}After the first comparison the array is:
{1, 5, 2, 3}What would be the array after the next comparison?
- {1, 2, 5, 3}
- {1, 5, 3, 2}
- {1, 3, 5, 2}
- {1, 3, 2, 5}