1 //Note: Hao2 //function: Display pyramids on the console3 //Date: 2018.08.094 5 Public classtriangle{6 Public Static voidMain (String args[]) {7 intlay=10, i,j,k;8 for(i=1;i<=lay;i++){9 for(k=1;k<=lay-i;k++){TenSystem.out.print (""); One } A for(j=1;j<= (i-1) *2+1;j++){ -System.out.print ("*"); - } the System.out.println (); - } - } -}
Operation Result:
1 //Note: Hao2 //function: Skeleton pyramid displayed on the console3 //Date: 2018.08.094 5 Public classkongtriangle{6 Public Static voidMain (String args[]) {7 intlay=10, i,j,k,m;8 for(i=1;i<=lay;i++){9 for(k=1;k<=lay-i;k++){TenSystem.out.print (""); One } A for(j=1;j<= (i-1) *2+1;j++){ - if(i==1| | i==lay) { -System.out.print ("*"); the } - Else{ - if(j==1| | j== (i-1) *2+1){ -System.out.print ("*"); + } - Else{ +System.out.print (""); A } at } - } - System.out.println (); - } - } -}
Operation Result:
1 //Note: Hao2 //function: Display the diamond on the console3 //Date: 2018.08.094 5 Public classdiamond{6 Public Static voidMain (String []args) {7 intlay=10, i,j,k;8 //Upper Part 9 Floor9 for(i=1;i<=lay-1;i++){Ten for(k=1;k<=lay-i;k++){ OneSystem.out.print (""); A } - for(j=1;j<= (i-1) *2+1;j++){ -System.out.print ("*"); the } - System.out.println (); - } - //lower half 10 layers + for(i=1;i<=lay;i++){ - for(k=1;k<=i-1;k++){ +System.out.print (""); A } at for(j=1;j<= (lay-i) *2+1;j++){ -System.out.print ("*"); - } - System.out.println (); - } - } in } -
Operation Result:
1 //Note: Hao2 //function: Display Hollow diamond on the console3 //Date: 2018.08.104 5 Public classkongdiamond{6 Public Static voidMain (String []args) {7 intlay=10, i,j,k;8 //Upper Part 9 Floor9 for(i=1;i<=lay-1;i++){Ten for(k=1;k<=lay-i;k++){ OneSystem.out.print (""); A } - for(j=1;j<= (i-1) *2+1;j++){ - if(j==1| | j== (i-1) *2+1){ theSystem.out.print ("*"); -}Else{ -System.out.print (""); - } + } - System.out.println (); + } A //lower half 10 layers at for(i=1;i<=lay;i++){ - for(k=1;k<=i-1;k++){ -System.out.print (""); - } - for(j=1;j<= (lay-i) *2+1;j++){ - if(j==1| | j== (lay-i) *2+1){ inSystem.out.print ("*"); -}Else{ toSystem.out.print (""); + } - } the System.out.println (); * } $ }Panax Notoginseng } -
Operation Result:
One, Java loop control statement practice