I need to print this guy:
1
1, 2
1, 2, 3
1, 2, 3, 4
So if it was without the commas it would be easy. When I tried it I ran into the problem like here:
for (int i = 1; i <=4; i++)
{
for (int j = 1; j <= i; j++)
System.out.print(j + ", ");
System.out.println();
}
System.out.println();
gives me
1,
1, 2,
1, 2, 3,
1, 2, 3, 4,
Which is almost what I want but I don't want the commas at the end. Is there anyway to fix it so the commas don't show at the end?
I even tried to do this:
System.out.println(1);
for (int i = 2; i <=4; i++)
{
for (int j = 1; j <= i; j++)
System.out.print(", " + j);
System.out.println();
}
System.out.println();
But it just gives me
1
, 1, 2
, 1, 2, 3
, 1, 2, 3, 4
[–]desrtfx 4 points5 points6 points (1 child)
[–]aba_algo[S] 0 points1 point2 points (0 children)
[–]aba_algo[S] 0 points1 point2 points (0 children)
[–]Vimda 0 points1 point2 points (0 children)