मराठी

Given that: String xa = "active" ; String xb = "passive"; int ct = xa.compareTo(xb); What will be the value of ct?

Advertisements
Advertisements

प्रश्न

Given that:

String xa = "active" ; String xb = "passive";

int ct = xa.compareTo(xb);

What will be the value of ct?

पर्याय

  • 15

  • 14

  • −14

  • −15

MCQ
Advertisements

उत्तर

−15

Explanation:

  • The Method: The compareTo() method compares two strings lexicographically (based on the ASCII/Unicode value of each character) starting from the very first character.
  • The Calculation: It finds the first position where the two strings differ. Here, they differ at the very first character: 'a' in "active" and 'p' in "passive". The method subtracts the Unicode value of 'p' (112) from the Unicode value of 'a' (97), which results in 97 - 112 = -15.
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 10: String Handling - Exercises [पृष्ठ २४५]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 10 String Handling
Exercises | Q 1. (ii) | पृष्ठ २४५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×