Find the greatest number based on the user input in Java
import java.util.Scanner;
public class FindHighestNumber{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the First Number : ");
int firstNumber=sc.nextInt();
System.out.println("Enter the Second Number : ");
int secondNumber=sc.nextInt();
System.out.println("Enter the Third Number : ");
int thirdNumber=sc.nextInt();
int [] array={firstNumber,secondNumber,thirdNumber};
int arrayValue=0;
int arrayMatch=0;
int count=0;
for(int i=0;i<array.length;i++){
arrayValue=array[i];
for(int j=0;j<array.length;j++){
arrayMatch=array[j];
if(arrayValue>arrayMatch){
count++;
}
}
if(count==(array.length-1)){
System.out.println("The greatest number is: "+arrayValue);
}
count=0;
}
}
}
Output:
Enter the First Number :
44
Enter the Second Number :
66
Enter the Third Number :
77
The greatest number is: 77
Comments
Post a Comment