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();
}
}
}
Lion-O - 30 Oct 2006 01:58 GMT
> 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 { ?

Signature
Groetjes, Peter
.\\ PGP/GPG key: http://www.catslair.org/pubkey.asc
Lew - 30 Oct 2006 02:24 GMT
>> why isn't the second part of my triangle not working?
>
[quoted text clipped - 6 lines]
>
> 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
Lew - 30 Oct 2006 02:34 GMT
> why isn't the second part of my triangle not working?
> import java.util.*;
[quoted text clipped - 15 lines]
>
> }
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
Patricia Shanahan - 30 Oct 2006 03:09 GMT
> why isn't the second part of my triangle not working?
> import java.util.*;
[quoted text clipped - 15 lines]
>
> }
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