Menu
Topics Index
...
`

Strings2058


If you need explanation Read this topic

If you need Answer Take test on this topic

Strings2058
What will be the output of following program?
public class EnterNewName {
    public static void main(String[] args) {
        String kiran = "SEARCHING";
        String kirankumar = "READING";
        String kk = "SEARCHING";
        System.out.print(kiran.compareTo(kk) + ", ");
        System.out.print(kiran.compareTo(kirankumar) + ", ");
        System.out.print(kirankumar.compareTo(kiran));
    }
}

A. 0, 1, -1
B. true, false, false
C. Some other output
D. Output can not be determined
E. Compilation Error or Runtime Error
Topic: Java compareTo() method

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer : A
as kiran and kk are same compareTo() return 0
ad in the other two cases once is less and hence 1 and the other time is greater so -1

Posted by Deepak Kumar Yadav    2014-06-20 03:50:42


ans:A  becoz compareTo()method returns a numeric value .

Posted by Nausheen Fathima    2014-06-20 06:02:09


Congratulations Deepak Kumar Yadav. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-23 04:41:57


© meritcampus 2019

All Rights Reserved.

Open In App