Java program that reads three different numbers and prints if they're all the same, all different or neither
Posted by Samath
Last Updated: February 12, 2021
  363

Write a java program that reads three different numbers and prints if they're all the same, all different or neither.

Code:

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        
        System.out.println("Enter first number: ");
        double num1 = input.nextDouble();
        
        System.out.println("Enter second number: ");
        double num2 = input.nextDouble();
        
        System.out.println("Enter third number: ");
        double num3 = input.nextDouble();
        input.close();
        
        if ((num1 == num2) && (num2 == num3))
        {
            System.out.println("All the same");
        }
        else if ((num1 != num2) && (num1 != num3))
        {
            System.out.println("All different");
        }
        else
        {
            System.out.println("Neither");
        }
    }
}