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
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