打印空心三角形

空心三角形图案

http://www.nowcoder.com/questionTerminal/2ccc5fca423e47f0b622fe6f151cfab4

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            for(int i = 0; i < n - 1; ++i){
                for(int j = 0; j < 2*n; ++j){
                    if(j == 0 || j == 2*i)
                        System.out.printf("*");
                    else
                        System.out.printf(" ");
                }
                System.out.println();
            }
            while(n-- > 0) System.out.printf("* ");
            System.out.println();
        }
    }
}
全部评论

相关推荐

05-22 12:44
已编辑
门头沟学院 golang
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务