I'm trying to find the smallest number from the inputs (5 inputs) of users. However, every time I click run and write down the numbers, the smallest number will always be "0". Here is my code:
import java.util.Scanner;
public class Q2_9 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int counter = 1;
double number;
double smallest = 0;
Scanner s = new Scanner(System.in);
while (counter < 6) {
System.out.println("Enter the number: ");
number = s.nextDouble();
if (smallest > number) {
smallest = number;
}
counter++;
}
System.out.println("The smallest number is " + smallest);
s.close();
}
}