I've got a homework assignment where I need to write a program using a loop that takes 10 integer values from a user and outputs the minimum of all values entered.
Here is what I've got:
import java.util.Scanner;
public class Num52
{
public static void main (String [] args )
{
int value;
int minValue;
Scanner scan = new Scanner(System.in);
for( int i = 0; i < 10; i++ )
{
System.out.print( "Enter a number as an integer > " );
value = scan.nextInt( );
if( value < minValue )
minValue = value;
}
System.out.println( "The minimum number is " + minValue );
}
}
You have forgotten to initialize minValue.
Try this in your for loop
Or you can intialize before for loop like this