题解 | #翻转金字塔图案#

翻转金字塔图案

https://www.nowcoder.com/practice/c4775776e4464537bfb6a5ba37c596c6

import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        while(sc.hasNextInt()){
            n = sc.nextInt();
            StringBuffer str = new StringBuffer();
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    if(j >= i){
                        str.append("* ");
                    } else {
                        str.append(" ");
                    } 
                }
                str.append("\n");
            }
            System.out.print(str.toString());
        }
    }
}
全部评论

相关推荐

09-13 13:10
南京大学 C++
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务