Largest of three numbers in Java
Here, you will get example program to find largest of three numbers in Java programming by using the logical operators and nested if-else.
This is a basic java program, Here we will get 3 numbers as input from the user and print the greatest of all three numbers as output.
Program to Find Largest of three numbers in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.util.*; class LargestThreeNumbers { public static void main(String args[]) { int a,b,c; System.out.println("Enter three numbers : "); Scanner in = new Scanner(System.in); a = in.nextInt(); b = in.nextInt(); c = in.nextInt(); if ( a > b && a > c ) System.out.println(a +" number is largest."); else if ( b > c && b > a ) System.out.println(b +" number is largest."); else if ( c > a && c > b ) System.out.println(c +" number is largest."); else System.out.println("Wrong Input!!!"); } } |
Output
Check out our other Java Programming Examples