English

Given that: String gk = "James Clerk Maxwell"; nk = gk.compareTolgnoreCase("k"); What will be the value of nk?

Advertisements
Advertisements

Question

Given that:

String gk = "James Clerk Maxwell";

nk = gk.compareTolgnoreCase("k");

What will be the value of nk?

Options

  • 1

  • 2

  • −1

  • −2

MCQ
Advertisements

Solution

−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
  Is there an error in this question or solution?
Chapter 10: String Handling - Exercises [Page 245]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 10 String Handling
Exercises | Q 1. (viii) | Page 245
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×