Posted: Thu Mar 11, 2010 8:46 pm Post subject: Loops program error no output
Hello I cant seem to find the error in my program I have tried everything I can think of I guess im just no good with loops...I would appreciate it if someone could take a look
Quote:
class Hello
{
public static void main (String args [])
{
System.out.println ("LoopProgram");
int alpha = 10;
int beta = 2;
int Multiplier = 5;
for (int counter = beta; counter >= alpha; counter -= 1)
{
System.out.print (counter*Multiplier + "");
}
}
}
When I compile it outputs LoopProgram but nothing else..
Any help is appreciated.
Sponsor Sponsor
chrisbrown
Posted: Thu Mar 11, 2010 8:55 pm Post subject: RE:Loops program error no output
This for loop will loop until (counter >= alpha) is false; in other words, until counter is less than alpha.
If counter starts with value 2 and alpha is 10, is counter greater or less than alpha?
slider203
Posted: Thu Mar 11, 2010 9:15 pm Post subject: Re: RE:Loops program error no output
This for loop will loop until (counter >= alpha) is false; in other words, until counter is less than alpha.
If counter starts with value 2 and alpha is 10, is counter greater or less than alpha?
The counter is less than alpha
so would the for staatment look like this:
Posted: Thu Mar 11, 2010 9:25 pm Post subject: RE:Loops program error no output
Getting there, but if counter starts at 2 and is decreasing each time, counter will never be greater than alpha. Try ... counter = alpha; counter >= beta; ...
slider203
Posted: Thu Mar 11, 2010 9:39 pm Post subject: RE:Loops program error no output
Ok thanks this really helped I'd give you karma but I dont have enough posts sorry