AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need help with loop

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
meena.desani
Guest





PostPosted: Mon Oct 30, 2006 6:34 am    Post subject: Need help with loop Reply with quote



why isn't the second part of my triangle not working?
import java.util.*;

public class triangle
{

public static void main(String[] args)
{
int nLines = 5;
for (int row = 1; row <= nLines; row++)
{
for (int star= 1; star <= row; star++)
System.out.print("*");
System.out.println();
}

}

}
Back to top
Lion-O
Guest





PostPosted: Mon Oct 30, 2006 6:58 am    Post subject: Re: Need help with loop Reply with quote



Quote:
why isn't the second part of my triangle not working?


Quote:
for (int row = 1; row <= nLines; row++)
{
for (int star= 1; star <= row; star++)
System.out.print("*");
System.out.println();
}


Note the missing { ?

--
Groetjes, Peter

..\\ PGP/GPG key: http://www.catslair.org/pubkey.asc
Back to top
Lew
Guest





PostPosted: Mon Oct 30, 2006 7:24 am    Post subject: Re: Need help with loop Reply with quote



Lion-O wrote:
Quote:
why isn't the second part of my triangle not working?


for (int row = 1; row <= nLines; row++)
{
for (int star= 1; star <= row; star++)
System.out.print("*");
System.out.println();
}


Note the missing { ?

Actually, the braces matched. The for loop has only one line, the

System.out.print().

Note that in the original post there were three opening braces and three
closing braces. Adding one opening brace would cause compilation failure.

- Lew
Back to top
Lew
Guest





PostPosted: Mon Oct 30, 2006 7:34 am    Post subject: Re: Need help with loop Reply with quote

meena.desani wrote:
Quote:
why isn't the second part of my triangle not working?
import java.util.*;

public class triangle
{

public static void main(String[] args)
{
int nLines = 5;
for (int row = 1; row <= nLines; row++)
{
for (int star= 1; star <= row; star++)
System.out.print("*");
System.out.println();
}

}

}

First of all, what do you mean by the "second part" of the loop, and in what
way is it not working?

Second of all, you really should use spaces to show indentation, not tabs, and
get things lined up in a way that makes sense. In your post, it looks as if
you intend the println() call to appear in the inner loop. That brings up

Third of all, you should enclose even one-line loop bodies in braces.
Combined with the aforementioned indentation fubar, it makes it extremely hard
to understand what you're trying to accomplish.

Please rephrase your question to indicate:
- What exactly you are trying to accomplish, and
- What exactly you are getting instead.

Oh, and you should name classes with an initial upper-case letter: "Triangle",
not "triangle".

Simply stating that "the second part of your triangle [is] not working"
doesn't give the rest of us enough information to help you. We need the details.

For what it's worth, I ran your code and it worked just fine, yielding the
output:

*
**
***
****
*****

- Lew
Back to top
Patricia Shanahan
Guest





PostPosted: Mon Oct 30, 2006 8:09 am    Post subject: Re: Need help with loop Reply with quote

meena.desani wrote:
Quote:
why isn't the second part of my triangle not working?
import java.util.*;

public class triangle
{

public static void main(String[] args)
{
int nLines = 5;
for (int row = 1; row <= nLines; row++)
{
for (int star= 1; star <= row; star++)
System.out.print("*");
System.out.println();
}

}

}


If you really mean "Why isn't it not working?" the answer is because the
loops are correct, assuming you wanted a triangle of asterisks, though
very untidy.

Patricia
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.