Submitted By: mhack_rances(viado)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
/* Generate Pyramid For a Given Number Example This Java example shows how to generate a pyramid of numbers for given number using for loop example. */ import java.io.BufferedReader; import java.io.InputStreamReader; public class GeneratePyramidExample { public static void main (String[] args) throws Exception{ BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in)); System.out.println("Enter Number:"); int as= Integer.parseInt (keyboard.readLine()); System.out.println("Enter X:"); int x= Integer.parseInt (keyboard.readLine()); int y = 0; for(int i=0; i<= as ;i++){ for(int j=1; j <= i ; j++){ System.out.print(y + "t"); y = y + x; } System.out.println(""); } } } /* Output of this example would be Enter Number: 5 Enter X: 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ---------------------------------------------- Enter Number: 5 Enter X: 2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 ---------------------------------------------- Enter Number: 5 Enter X: 3 0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 */ |
Amazing, just what i needed
Really i provided me what i needed with a neat explanation.
perfect with neat explanation
Perfect Explanation
cool!thanks
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
Very good explanation….
Perfect!
Thanx mate…
1
2 2
3 3
4 4
5 5
1
2 2
3 3
4 4
5 5
Very well done. Examples helped me a lot.
verry nice and good explanation
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.
1
121
12321
1234321
123454321
please print this i need the code of this
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();
}
}
}
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();
}
}
}
5
45
345
2345
12345
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
a code help please
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();
}
}
}
1
21
321
4321
54321
i want to print this then what i have to do??
i want this format
1
232
45654
7890987
123454321
can you help me?
Pls print this patter
1
121
12321
1234321
12321
121
1