0

Please help me making code for this pattern

1 22 333 4444 55555

20th Jan 2017, 7:55 PM
Aman Agarwal
Aman Agarwal - avatar
7 Answers
+ 2
If you want a pyramid you'll need more numbers: int max = 5; for(int i = 1; i <= max; i++){ for(int t = 0; t < max-i; t++){ System.out.print(" "); } for(int t = 0; t < i*2-1; t++){ System.out.print(i); } System.out.println(); }
20th Jan 2017, 8:16 PM
Robobrine
Robobrine - avatar
0
Well, it'll probably not line up like this as ' ' (empty space) is normaly as big as every other character if you output to the console, but here you go: int max = 5; for(int i = 1; i <= max; i++){ for(int t = 0; t < max-i; t++){ System.out.print(" "); } for(int t = 0; t < i; t++){ System.out.print(i); } System.out.println(); }
20th Jan 2017, 8:02 PM
Robobrine
Robobrine - avatar
0
not working bro
20th Jan 2017, 8:05 PM
Aman Agarwal
Aman Agarwal - avatar
0
You did copy this into the main method and used java to run it, right?
20th Jan 2017, 8:07 PM
Robobrine
Robobrine - avatar
0
lining is not probably but totally different . Its 1 22 333 4444 55555
20th Jan 2017, 8:07 PM
Aman Agarwal
Aman Agarwal - avatar
0
Told you, but look what happens if you copy the output into this answer field: 1 22 333 4444 55555 Exactly what you wrote!
20th Jan 2017, 8:14 PM
Robobrine
Robobrine - avatar
0
yup.. you are right.. thanks for help.
20th Jan 2017, 8:15 PM
Aman Agarwal
Aman Agarwal - avatar