Create a program that will read the values of A and B. Compare the two values of A & B then print which of the values is higher including the remark “Higher”
import java.util.Scanner;
public class Compare {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next(),
b = scanner.next();
if (a.equals(b)) {
System.out.println("A equals to B");
} else if (a.compareTo(b)) {
System.out.println("A higher than B");
} else if (b.compareTo(a)) {
System.out.println("B higher than A");
}
}
}
Comments
Leave a comment