Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Biggest of three numbers using Logical Operators in Java

This java program finds largest of three numbers and then prints it. If the entered numbers are unequal then "numbers are not distinct" is printed.
  1. import java.util.Scanner;
  2. class LargestOfThreeNumbers
  3. {
  4. public static void main(String args[])
  5. {
  6. int x, y, z;
  7. System.out.println("Enter three integers ");
  8. Scanner in = new Scanner(System.in);
  9. x = in.nextInt();
  10. y = in.nextInt();
  11. z = in.nextInt();
  12. if ( x > y && x > z )
  13. System.out.println("First number is largest.");
  14. else if ( y > x && y > z )
  15. System.out.println("Second number is largest.");
  16. else if ( z > x && z > y )
  17. System.out.println("Third number is largest.");
  18. else
  19. System.out.println("Entered numbers are not distinct.");
  20. }
  21. }