Advertisement
newbninja

Question 3.2

Oct 16th, 2023
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NumberEqualityChecker {
  4.     public static void main(String[] args) {
  5.         // Create a Scanner object to read input from the user
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         // Prompt the user to enter the first number
  9.         System.out.print("Enter the first number: ");
  10.         int num1 = scanner.nextInt();
  11.  
  12.         // Prompt the user to enter the second number
  13.         System.out.print("Enter the second number: ");
  14.         int num2 = scanner.nextInt();
  15.  
  16.         // Prompt the user to enter the third number
  17.         System.out.print("Enter the third number: ");
  18.         int num3 = scanner.nextInt();
  19.  
  20.         // Close the Scanner
  21.         scanner.close();
  22.  
  23.         // Check if all numbers are equal
  24.         if (num1 == num2 && num2 == num3) {
  25.             System.out.println("All numbers are equal.");
  26.         }
  27.         // Check if all numbers are different
  28.         else if (num1 != num2 && num2 != num3 && num1 != num3) {
  29.             System.out.println("All numbers are different.");
  30.         }
  31.         // If neither all are equal nor all are different
  32.         else {
  33.             System.out.println("Neither all are equal nor all are different.");
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement