Answers for "find highest and lowest of five integers using java loops"

0

find highest and lowest of five integers using java loops

//Declare max as Minimum and min as Maximum

int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;

//Declare Scanner to take input from user

Scanner sc = new Scanner(System.in);

System.out.print("Enter 5 integers: ");

//for loop that runs 5 times to take input from user

for (int i = 0; i < 5; ++i) {

int num = sc.nextInt();

//Check if the number is greater than max

if (max < num)

max = num;

//Check if the number is smaller than min

if (min > num)

min = num;

}

//Print the Highest number which is stored in max

System.out.println("Highest integer is " + max);
//Print the Lowest number which is stored in min

System.out.println("Lowest integer is " + min);
Posted by: Guest on November-26-2020

Code answers related to "find highest and lowest of five integers using java loops"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language