题解 | #K形图案#

K形图案

https://www.nowcoder.com/practice/753cc2662d9949fe826a85f815db0ca4

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = 0;
        while (s.hasNext()) {
            n = s.nextInt();
            for (int i = 0; i <= n; i++) {
                for (int j = n - i; j >= 0; j--) {
                    System.out.print("* ");
                }
                System.out.println();
            }
            for (int i = 0; i < n; i++) {
                for (int j = n; j <= n + 1 + i; j++) {
                    System.out.print("* ");
                }
                System.out.println();
            }
        }
    }
}

全部评论

相关推荐

06-19 14:58
门头沟学院 Java
点赞 评论 收藏
分享
04-28 11:34
西北大学 运营
牛客4396号:不好意思,这个照片猛一看像丁真
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-20 20:15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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