题解 | #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();
            }
        }
    }
}

全部评论

相关推荐

04-27 08:59
常州大学 Java
牛客139242382号:《两门以上汇编语言》
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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