- 最後登錄
- 2022-10-22
- 在線時間
- 0 小時
- 註冊時間
- 2011-10-13
- 閱讀權限
- 30
- 精華
- 0
- UID
- 10420414
- 帖子
- 663
- 積分
- 1128 點
- 潛水值
- 20810 米
| 本帖最後由 theloserbm 於 2014-6-14 06:36 PM 編輯
堅持1,2,3版本
並無恥抄襲var和func名字- public class Triangle {
- public static void main(String[] args) {
- int small_height = Integer.parseInt(args[0]);
- int height = Integer.parseInt(args[1]);
-
- big_tri(small_height, height);
- }
-
- public static void big_tri(int small_height, int height) {
- for (int i=1; i<=height; i++) {
- small_tri(small_height, height, i);
- }
- }
-
- public static void small_tri(int small_height, int height, int line) {
- for (int i=1; i<=small_height; i++) {
- // pre space
- print_space((height - line) * small_height);
-
- for (int j=1; j<=line; j++) {
- print_space(small_height - i);
- print_star(1 + (i-1)*2);
- print_space(small_height - i + 1);
- }
- System.out.println();
- }
- }
-
- public static void print_space(int count) {
- for (int i=1; i<=count; i++) {
- System.out.print(' ');
- }
- }
-
- public static void print_star(int count) {
- for (int i=1; i<=count; i++) {
- System.out.print('*');
- }
- }
- }
複製代碼 結果多美妙- C:\Users\Icecool\Desktop>java Triangle 3 5
- *
- ***
- *****
- * *
- *** ***
- ***** *****
- * * *
- *** *** ***
- ***** ***** *****
- * * * *
- *** *** *** ***
- ***** ***** ***** *****
- * * * * *
- *** *** *** *** ***
- ***** ***** ***** ***** *****
複製代碼 ... |
|