Advertisements
Advertisements
प्रश्न
Given that:
String gk = "James Clerk Maxwell";
nk = gk.compareTolgnoreCase("k");
What will be the value of nk?
विकल्प
1
2
−1
−2
MCQ
Advertisements
उत्तर
−1
Explanation:
The compareToIgnoreCase() method compares the very first characters of both strings alphabetically after converting them to lowercase. Since 'j' (from "James") comes exactly one position before 'k' in the alphabet, the method performs the subtraction ('j' − 'k'), which equals −1.
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 10: String Handling - Exercises [पृष्ठ २४५]
