For Loop

# Generate Pyramid For a Given Number Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

• Anonymous says:

Amazing, just what i needed

• Anonymous says:

Really i provided me what i needed with a neat explanation.

• Anonymous says:

perfect with neat explanation

• Anonymous says:

Perfect Explanation

• Anonymous says:

cool!thanks

• Anonymous says:

Gr8 Example. This is what exactly i needed. Thx a lot.

However it didn’t worked when i take java.util.ArrayList.

It worked for java.util.List

~RamKumar

• Anonymous says:

Very good explanation….

• Anonymous says:

Perfect!

• Anonymous says:

Thanx mate…

• Anonymous says:

1
2 2
3 3
4 4
5 5

• Anonymous says:

1
2 2
3 3
4 4
5 5

• Anonymous says:

Very well done. Examples helped me a lot.

• Michael Quilla says:

verry nice and good explanation

• asd says:

Since I am a student of 12th, it wasn’t that easy for me to understand.
But yes, it has been done in an explanatory manner!
And, so I could make it out then.

• brijesh says:

1
121

12321
1234321
123454321

please print this i need the code of this

• Sai Kiran says:

package com.saikiran.loops;

public class Triangle {
public static void main(String[] args) {

for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
System.out.print(j);
if(i!=1){
if(j==i){
for(int k=0;k<(j-1);k++){
System.out.print(j-(k+1));
}
}
}
}
System.out.println();
}

}
}

• Vivek Chawla says:

class Abc
{
public static void main(String args[])
{
for(int i=1;i<6;i++)
{
for(int k=1;k<=1;k++)
{
system.out.print(k);
}
for(int j=i;j>1;j–)
{
System.out.print(j-1);
}
System.out.println();
}
}
}

• sabeeha says:

5
45
345
2345
12345

• Leah Grace says:

1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910

• Ajay Rajput says:

public class Raj{
public static void main(String args []){
for(int i=1;i<=10;i++){
for(int j=1;j<=i ;j++)
System.out.print(j);
System.out.println();
}
}
}

• yagnesh sojitra says:

1
21
321
4321
54321

i want to print this then what i have to do??

• SAMI D says:

i want this format
1
232
45654
7890987
123454321

can you help me?

• Sudesh Bishnoi says:

Pls print this patter
1
121
12321
1234321
12321
121
1