Menu
Question Index
...

What will be the output of the following program?

public class Fruit {
    public static void main(String[] args) {
        String fruit = "Apple";
        String fruit1 = "Apple";
        if (fruit.compareTo(fruit1) == 0) {
            System.out.println(fruit + " and " + fruit1 + " are equal");
        } else if (fruit.compareTo(fruit1) >= 0) {
            System.out.println(fruit + " is greater than " + fruit1);
        } else if (fruit.compareTo(fruit1) < 0) {
            System.out.println(fruit + " is less than " + fruit1);
        }
    }
}


Apple is less than Apple
Apple is greater than Apple
Apple and Apple are equal
Apple and Apple are equal
Apple is greater than Apple
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java compareTo() method

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App