I am trying to take 10 integers from the user's input and find the minimum value using a for loop.
I am struggling to correctly write the if statement. It is supposed to take the first input and make that the smallest and compare the next inputs to that.
My final print statement just prints the last number entered.
Scanner scan = new Scanner(System.in);
int smallest = 0;
int number = 0;
for (int i = 1; i <= 10; i++) {
System.out.print("Enter a number > ");
number = scan.nextInt();
if (number < smallest) {
smallest = number;
} else {
smallest = number;
}
}
System.out.println("The minimum is " + smallest);