首页 > 编程语言 > 详细

【Java3】打印三角形

时间:2015-06-29 21:52:18      阅读:150      评论:0      收藏:0      [点我收藏+]

1.

 1 import java.io.*;
 2 public class Practice {
 3     public static void main(String[] args){
 4         for(int i=0; i<5; ++i){
 5             for(int j=0; j<i+1; ++j){
 6                 System.out.print(‘*‘);
 7             }
 8             System.out.println();
 9         }
10     }
11 }
12 *
13 **
14 ***
15 ****
16 *****

2.

 1 import java.io.*;
 2 public class Practice {
 3     public static void main(String[] args){
 4         for(int i=1; i<=5; ++i){
 5             for(int j=1; j<=5-i; ++j){
 6                 System.out.print(‘ ‘);
 7             }
 8             for(int k=0; k<i; ++k){
 9                 System.out.print(‘*‘);
10             }
11             System.out.println();
12         }
13     }
14 }
15     *
16    **
17   ***
18  ****
19 *****

3.

 1 import java.io.*;
 2 public class Practice {
 3     public static void main(String[] args){
 4         for(int i=1; i<=5; ++i){
 5             for(int j=1; j<=(9-((i-1)*2+1))/2; ++j){
 6                 System.out.print(‘ ‘);
 7             }
 8             for(int k=1; k<=(i-1)*2+1; ++k){
 9                 System.out.print(‘*‘);
10             }
11             System.out.println();
12         }
13     }
14 }
15 
16     *
17    ***
18   *****
19  *******
20 *********

 

【Java3】打印三角形

原文:http://www.cnblogs.com/mtc-dyc/p/4608391.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!