标签:image == stat 菱形 i++ code ++ rgs system
1 //注释:hao 2 //功能:控制台上显示金字塔 3 //日期:2018.08.09 4 5 public class Triangle{ 6 public static void main(String args[]){ 7 int lay=10,i,j,k; 8 for(i=1;i<=lay;i++){ 9 for(k=1;k<=lay-i;k++){ 10 System.out.print(" "); 11 } 12 for(j=1;j<=(i-1)*2+1;j++){ 13 System.out.print("*"); 14 } 15 System.out.println(); 16 } 17 } 18 }
运行结果:
1 //注释:hao 2 //功能:控制台上显示镂空金字塔 3 //日期:2018.08.09 4 5 public class KongTriangle{ 6 public static void main(String args[]){ 7 int lay=10,i,j,k,m; 8 for(i=1;i<=lay;i++){ 9 for(k=1;k<=lay-i;k++){ 10 System.out.print(" "); 11 } 12 for(j=1;j<=(i-1)*2+1;j++){ 13 if(i==1||i==lay){ 14 System.out.print("*"); 15 } 16 else{ 17 if(j==1||j==(i-1)*2+1){ 18 System.out.print("*"); 19 } 20 else{ 21 System.out.print(" "); 22 } 23 } 24 } 25 System.out.println(); 26 } 27 } 28 }
运行结果:
1 //注释:hao 2 //功能:控制台上显示菱形 3 //日期:2018.08.09 4 5 public class diamond{ 6 public static void main(String []args){ 7 int lay=10,i,j,k; 8 //上半部分 9层 9 for(i=1;i<=lay-1;i++){ 10 for(k=1;k<=lay-i;k++){ 11 System.out.print(" "); 12 } 13 for(j=1;j<=(i-1)*2+1;j++){ 14 System.out.print("*"); 15 } 16 System.out.println(); 17 } 18 //下半部分 10层 19 for(i=1;i<=lay;i++){ 20 for(k=1;k<=i-1;k++){ 21 System.out.print(" "); 22 } 23 for(j=1;j<=(lay-i)*2+1;j++){ 24 System.out.print("*"); 25 } 26 System.out.println(); 27 } 28 } 29 } 30
运行结果:
1 //注释:hao 2 //功能:控制台上显示空心菱形 3 //日期:2018.08.10 4 5 public class KongDiamond{ 6 public static void main(String []args){ 7 int lay=10,i,j,k; 8 //上半部分 9层 9 for(i=1;i<=lay-1;i++){ 10 for(k=1;k<=lay-i;k++){ 11 System.out.print(" "); 12 } 13 for(j=1;j<=(i-1)*2+1;j++){ 14 if(j==1||j==(i-1)*2+1){ 15 System.out.print("*"); 16 }else{ 17 System.out.print(" "); 18 } 19 } 20 System.out.println(); 21 } 22 //下半部分 10层 23 for(i=1;i<=lay;i++){ 24 for(k=1;k<=i-1;k++){ 25 System.out.print(" "); 26 } 27 for(j=1;j<=(lay-i)*2+1;j++){ 28 if(j==1||j==(lay-i)*2+1){ 29 System.out.print("*"); 30 }else{ 31 System.out.print(" "); 32 } 33 } 34 System.out.println(); 35 } 36 } 37 } 38
运行结果:
标签:image == stat 菱形 i++ code ++ rgs system
原文地址:https://www.cnblogs.com/ioq2545/p/9456973.html