Write a Java program that accepts three numbers and check All numbers are equal or not


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1.  
  2. import java.util.Scanner;
  3. public class JavaExcercise {
  4.  
  5. public static void main(String[] args)
  6. {
  7. Scanner in = new Scanner(System.in);
  8.  
  9. System.out.print("Enter first number: ");
  10. int num1 = in.nextInt();
  11. System.out.print("Enter second number: ");
  12. int num2 = in.nextInt();
  13. System.out.print("Enter third number: ");
  14. int num3 = in.nextInt();
  15.  
  16. if (num1 == num2 && num1 == num3)
  17. {
  18. System.out.println("All numbers are equal");
  19. }
  20. else if ((num1 == num2) || (num1 == num3) || (num3 == num2))
  21. {
  22. System.out.println("Neither all are equal or different");
  23. }
  24. else
  25. {
  26. System.out.println("All numbers are different");
  27. }
  28. }
  29. }

Result

java techstudy.org

     





Related Topics




Popular Posts