java - using a loop get a user to input an integer 10 times then get the minimum -


i've got homework assignment need write program using loop takes 10 integer values user , outputs minimum of values entered.

here 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 = 0; < 10; i++ )    {        system.out.print( "enter number integer > " );           value = scan.nextint( );        if( value < minvalue )        minvalue = value;        }        system.out.println( "the minimum number " + minvalue );     }  } 

you have forgotten initialize minvalue.

try in loop

if (i == 0)     minvalue = value; 

or can intialize before loop this

minvalue = interger.max_value; //this more efficient code. 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -