Jump to content


Check out our Community Blogs

welshguy

Member Since 14 Nov 2007
Offline Last Active Nov 14 2007 06:57 AM
-----

Topics I've Started

For Loop Help

14 November 2007 - 06:19 AM

I'm trying to achieve this:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

So far i have written this code:

public static void main(String[] args)
{
for (int rowNumber = 1; rowNumber <= 10; rowNumber++)
{
for (int colNumber = 1; colNumber <= 5; colNumber++)
{
System.out.println("" + rowNumber);

The output I had is as follows:

1
1
1
1
1
2
2
2
2
2
3
3
3
3
3
4
4
4
4
4
5
5
5
5
5
6
6
6
6
6
7
7
7
7
7
8
8
8
8
8
9
9
9
9
9
10
10
10
10
10

Clearly this is wrong & as i'm not a very good Java programmer i'm not sure how to correct this

Any help would be appreciated!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download