Java program to find largest number between 2 numbers

Java program to find largest number between 2 numbers

Program:-

import java.util.Scanner;

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


Output:-

Enter 1st number
2
Enter 2nd number
1
The largest number:2

Output:-

Enter 1st number
29
Enter 2nd number
36
The largest number:36


Output:-

Enter 1st number
52
Enter 2nd number
52
The largest number:52

Output:-

Enter 1st number
-56
Enter 2nd number
662
The largest number:662



Learn Java:-
Java codes

Java Programs:-
List of Java Programs

Leave reply

Add your comments here

Back to Top