倒金字塔

翻转金字塔图案

http://www.nowcoder.com/questionTerminal/c4775776e4464537bfb6a5ba37c596c6

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();
            StringBuilder sb = new StringBuilder("");
            while(sb.length() < n*2) sb.append("* ");
            while(n-- > 0){
                System.out.println(sb);
                int len = sb.length();
                sb.delete(len - 2, len);
                sb.insert(0, " ");
            }
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 14:35
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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