[QUOTE=Fordy252;20042]hello, i am new to java and i am having serious problems with nested loops. I just can't seem to get my head around them. The following pyramids are problems for homework and i am already stuck on the first pattern.. My attempted code is below and i can only seem to get the pyramid to print out the next number repeating on the next line.. I would really apreciate if someone could help me please and any tips for the best ways to go about solving these problems.. thank you..
(Printing four patterns using loops) Use nested loops that print the following patterns in four separate programs:
Pattern I Pattern II Pattern III Pattern IV
1 1 2 3 4 5 6 1 1 2 3 4 5 6
1 2 1 2 3 4 5 2 1 1 2 3 4 5
1 2 3 1 2 3 4 3 2 1 1 2 3 4
1 2 3 4 1 2 3 4 3 2 1 1 2 3
1 2 3 4 5 1 2 5 4 3 2 1 1 2
1 2 3 4 5 6 1 6 5 4 3 2 1 1
Pattern 3
public class num2
{
public static void main(String[] args)
{
int x,i,j,k;
for(i=0;i<6;i++)
{
x=6;
for(j=i+1;j<6;j++)
{
x--;
System.out.print(" ");
}
for(k=0;k<=i;k++)
{
System.out.print(x--);
}
System.out.println();
}
}
}