triangle numbers in java
I am new to Java and now I want to learn better for loop. I made some
examples , but I don't know how to do a triangle that look like this: for
n=6:
111111
22222
3333
222
11
6
My code until now:
class Pyramid
{
public static void main (String[] args)
{
int i,n=9,j;
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++) {
System.out.print(i); }
System.out.print("\n");
}}}
But what I managed to do it looks like this:
666666
55555
4444
333
22
1
How to make it in reverse order and to print the given number n when just
one character has to be print?
No comments:
Post a Comment