hi
i am doing this array program where the user has to prompt for 5 numbers and to store them in an array. the program will then print out the 5 numbers entered and the smallest one entered. here is my codes and the output. tell me why i am not getting the required output
the output is not what is supposed to output. any hl\elp and understanding would be appreciated.
int value[]= {1,2,3, 4,5};
int i = 0;
int smallest = 1;
for(i=0; i<5; i++)
{
System.out.println("enter a number");
value[i] = userinput.nextInt();
if(i == 1)
{
smallest = value[i];
}
if(value[i] < smallest)
{
smallest = value[i];
}
System.out.println("the smallest value is "+ value[i]);
}
here is the output
enter a number
1
the smallest value is 1
enter a number
2
the smallest value is 2
enter a number
3
the smallest value is 3
enter a number
4
the smallest value is 4
enter a number
5
the smallest value is 5
BUILD SUCCESSFUL (total time: 9 seconds)


