Java program to find largest number between 3 numbers

find maximum of 3 number in java

Java code for finding largest number of 3

Program:-

import java.util.Scanner;

class group{
public static void main(String ang[]){
Scanner data= new Scanner(System.in);
int num1, num2,num3;
// Read 1st number
System.out.println("Enter 1st number");
num1=data.nextInt();
// Read 2nd number
System.out.println("Enter 2nd number");
num2=data.nextInt();
//Read 3rd number
System.out.println("Enter 3rd number");
num3=data.nextInt();
// Find largest number
if(num1>num2 && num1>num3)
System.out.println("The largest number:"+num1);
else if(num2>num1 && num2>num3)
System.out.println("The largest number:"+num2);
else
System.out.println("The largest number:"+num3);
}
}

Output:-
Enter 1st number
56
Enter 2nd number
89
Enter 3rd number
45
The largest number:89


Enter 1st number
48
Enter 2nd number
25
Enter 3rd number
16
The largest number:48

Enter 1st number
25
Enter 2nd number
89
Enter 3rd number
98
The largest number:98

Enter 1st number
45
Enter 2nd number
89
Enter 3rd number
45

The largest number:89

Leave reply

Add your comments here

Back to Top