Java學習筆記(四)---列印圖形

來源:互聯網
上載者:User

標籤:ica   tab   gpo   span   計算   bsp   --   class   java   

 1   //1.菱形 2   public static void Lingxing(int size){ 3     if(size % 2 == 0){ 4       size++;//計算菱形大小 5     } 6     //輸出菱形上半部 7     for (int i = 0; i < size/2 + 1; i++) { 8       for (int j = size/2 + 1; j > i + 1; j--) { 9         System.out.print(" ");//輸出左上方位置的空白10       }11       for (int j = 0; j < 2*i + 1; j++) {12         System.out.print("*");//輸出菱形上半部13       }14       System.out.println();// 換行15     }16     // 輸出菱形下半部17     for (int i = size/2 + 1; i < size; i++) {18       for (int j = 0; j < i - size/2; j++) {19         System.out.print(" ");// 輸出菱形左下角空白20       }21       for (int j = 0; j < 2*size-1 - 2*i ; j++) {22         System.out.print("*");// 輸出菱形下半部23       }24       System.out.println();25     }26   }27 28   // 2.九九乘法表29   public static void MultiplicationTable(){30     for (int i = 1; i <= 9; i++) {31       for (int j = 1; j <= i; j++) {32         System.out.print(j+"x"+i+"="+i*j+"\t");// \t 跳到下一個TAB位置33       }34       System.out.println("");35     }36   }37 38   //3. 列印三角形39   public static void Triangle(int n){40     for (int i = 0; i <= n; i++) {41       for (int j = n; j >= i; j--) {42         System.out.print(" ");//建立1號圖形43       }44       for (int j = 1; j <= i; j++) {45         System.out.print("*");//建立2號圖形46       }47       for (int j = 1; j < i; j++) {48         System.out.print("*");//建立3號圖形49       }50       System.out.println("");51     }52   }53 54   //4.列印倒立的三角形55   public static void InvertedTriangle (int i) {56     //列印倒立的三角形57     for (int m = 1; m <= i; m++) {58        //列印空格59        for (int n = 0; n <= m; n++) {60            System.out.print(" ");61        }62        //列印*63        for (int x = 1; x <= 2*(i - m) + 1; x++) {64            System.out.print("*");65        }66        System.out.println();67     }  68   }69   70   //5.列印平行四邊形71   public static void Parallelogram (int n) {72     //外層迴圈 每次打出一個*73     for (int i = 1; i <=n; i++) {74       //填充空格75       for (int j = 1; j <= n - i; j++) {76           System.out.print(" ");77       }78       //內層迴圈 每次列印一個*79       for (int k = 1; k <=n; k++) {80           System.out.print("*");81       }82       System.out.println();83     }84   }85 86   //6.列印平行四邊形87   public static void Rectangle (int n) {88     //外層迴圈 每次打出一個*89     for (int i = 1; i <=n; i++) {90       //外層迴圈 每次輸出一行*91       System.out.print("*");92 93       //內層迴圈 每次列印一個*94       for (int k = 1; k <=n; k++) {95           System.out.print("*");96       }97       System.out.println();98     }99   }

 

Java學習筆記(四)---列印圖形

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.