
hoe to find largest number without using array

Hi Friend,
Try the following code:
import java.util.*;
class FindLargestAndSmallest{
public static void main(String[] args){
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
System.out.println("Enter 5 numbers:");
Scanner input=new Scanner(System.in);
for(int i=1;i<=5;i++){
int num=input.nextInt();
if (num < min) {
min = num;
}
if (num > max) {
max = num;
}
}
System.out.println("Smallest Number is: "+min);
System.out.println("Largest Number is: "+max);
}
}
Thanks