I am trying to create a Java code using a loop that will accept five integers input from console and return the smallest and the largest. I am having a problem with the code coming together.Thank you
import java.util.*;
public class Highest_LowestofFiveIntegers {
public static void main(String[] args) {
System.out.print("Enter five integers separated by a
space i.e. 2 6 55 1 3 910: ");
int number = 0;
number = input.nextInt();
int max = 0;
int min = 0;
for (int x = 0; x<5; x++){
if (x == 0 || number > max){
max = number;
}
if (x == 0 || number < min){
min = number;
}
}
System.out.println("Highest value: " + max);
System.out.println("Lowest value: " + min);
}
}
Put
number = input.nextInt();in theforloop; not before it.