Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Loops program error no output
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
slider203




PostPosted: 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
Sponsor
sponsor
chrisbrown




PostPosted: Thu Mar 11, 2010 8:55 pm   Post subject: RE:Loops program error no output

for (int counter = beta; counter >= alpha; counter -= 1)

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




PostPosted: Thu Mar 11, 2010 9:15 pm   Post subject: Re: RE:Loops program error no output

methodoxx @ Thu Mar 11, 2010 8:55 pm wrote:
for (int counter = beta; counter >= alpha; counter -= 1)

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:

for (int counter = beta; counter <= alpha; counter -= 1)

never mind that didnt work so well either...
chrisbrown




PostPosted: 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




PostPosted: 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 Sad
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: