Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
medium

String Comparison

Mark
< Prev
Next >

A program compares two distinct String objects using the compareTo method to determine lexicographical order.

What is printed when the following Java program is compiled and run?

public class QuestionTrace {

    public static void main(String[] args) {
        String a = "Apple";
        String b = "Banana";
        int val = a.compareTo(b);
        System.out.println(val < 0);
    }
}
A

-1

B

0

C

true

D

false

Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|