Answer to Question #277580 in Java | JSP | JSF for kaikai

Question #277580


 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”


1
Expert's answer
2021-12-10T00:36:37-0500
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");
  }
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS