import java.util.Scanner; //import class
public class HighLow {
public static void main(String[] args)
{
//create a scanner object
Scanner input = new Scanner (System.in);
//initialize array
int [ ] num = new int [5];
//input until 5 numbers since i is less than the length of array {0,1,2,3,4,5}
for (int i = 0; i < num.length; i++){
System.out.println ("Enter number:");
num [i] = input.nextInt( );
}
int max = 0;
//find largest integer
for (int i=0; i < num.length; i++){
if (num [i] > max){
max = num [i];
}
}
System.out.println ("Largest is: " + max);
int low = Integer.MAX_VALUE;
//find lowest integer
for (int i = 0; i < num.length; i++){
if (num[i] < low){
low = num[i];
}
}
System.out.println ("Smallest is: " + low);
}
}
No comments:
Post a Comment