हिंदी

What will be the output of the following program snippet? strl = "AMAN" str2 = "AMIT"System.out.println(strl.compareTo(str2)); - Computer Applications

Advertisements
Advertisements

प्रश्न

What will be the output of the following program snippet? 

strl = "AMAN"8
str2 = "AMIT"
System.out.println(strl.compareTo(str2));

विकल्प

  • 8

  • 0

  • −8

  • 2

MCQ

उत्तर

−8

Explanation:

  1. If the first string has fewer ASCII characters than the second one, compareTo() gives a negative number.
  2. "AMAN" and "AMIT" differ in their third characters, 'A' and 'I.' The compareTo() method will return the ASCII code of 'A' minus the ASCII code of 'I', which is 65 - 73 = −8.
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 4: String Handling - EXERCISES [पृष्ठ २८६]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
अध्याय 4 String Handling
EXERCISES | Q I. 7. | पृष्ठ २८६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×