java print pyramid or print a pyramid with numbers (Small records in Java learning) Wang Coli (Star star)
:
The code is as follows:
1 classStar82 {3 Public Static voidMain (string[] args)4 {5 /*Space6 * 1 2*i-1 3 4-1 4-i7 * * * 3 2 4-28 * * * * 5 1 4-39 ******* 7 0 4-4Ten */ One //the first layer of loop control is the number of rows A for(inti = 1;i<=5;i++){ - - //number of spaces to print the - for(intj=5;j>i;j--){ - -System.out.print (""); + } - + //Print * Numbered A for(intJ =1;j<=2*i-1;j++){ atSystem.out.print ("*"); - } - - //line Break - System.out.println (); - } - } to}
:
The code is as follows:
1 classStar82 {3 Public Static voidMain (string[] args)4 {5 /* 6 1 i= 1 07 1 i= 2 18 123 i= 3 29 1234 321 i= 4 3Ten 12345 4321 One 123456 54321 A */ - //control number of rows - for(inti = 1; i<=6; i++){ the - //Print a space - for(intJ= 1; j<=6-i;j++){ - +System.out.print (""); - } + A //Printing numbers: The law of the preceding numbers at for(intj=1;j<=i;j++){ - - System.out.print (j); - } - - //the law of the numbers behind in for(intj=i-1;j>=1;j--){ - to System.out.print (j); + } - the System.out.println (); * } $ }Panax Notoginseng}
Java print pyramid or print a pyramid with numbers (Small records in Java learning)