Click to See Complete Forum and Search --> : Basic Problem(Java101)


ed81
11-04-2005, 09:22 PM
Hi:

Can anyone Hlep me please :
I have this program for school that i have to get working, i am starting to learn java and i am a little confuse. I need to make the user enter 5 numbers and then show the smallest.. This is what i have:

import java.util.Scanner;
public class Smaller {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int c;
System.out.println("How many numbers you wish to enter?");
c = input.nextInt();
int n;

for (int counter = 1; counter<=c; counter++)
{
System.out.println("Please Enter the next number");
n = input.nextInt();


// need to compare with small here, update the smaller # to small


}
}
}

I need to get the second part right.. Thanks for your time!!
Regards
Ed

Oak
11-05-2005, 04:45 PM
See attached.

All you really needed to do was check if each input was smaller than the last and store it in a separate variable.

ed81
11-07-2005, 07:13 PM
Thank you very much oak eventhough my professor said not to use constructor or new things but only those we have learned this is going to help me a million to understand it and try to create the program the way he wants it. I see your point.. someday i will be able to run programs the way you do :P .. I am just a newbie :P

Best Regards
Ed