首页 > 编程知识 正文

金字塔代码 java,字符金字塔程序

时间:2023-05-03 15:04:56 阅读:279491 作者:3163

java代码部分(金字塔) package transfer;public class transferpyramid { public static void main(String[] args) { // TODO Auto-generated method stub int j = 10;//j为金字塔高度 System.out.println("-------------金字塔------------"); print1(j); System.out.println("-------------倒金字塔-----------"); print2(j); } public static void print1(int e) { for (int f = 1; f <= e; f++) { for (int g = 6+e - f; g > 0; g--) { System.out.print(" "); }//此处6为调整间距所设,可随意更改 for (int g = 1; g <= 2 * f - 1; g++) { System.out.print("*"); } System.out.println(); } } public static void print2(int e) { for (int f = e; f > 0; f--) { for (int g = 0; g < 6+e - f; g++) { System.out.print(" "); } for (int g = 1; g <= 2 * f - 1; g++) { System.out.print("*"); } System.out.println(); } }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。