题解 | #牛牛的字符菱形#

牛牛的字符菱形

https://www.nowcoder.com/practice/11a5040fa894430f9d25fda1be37ddc8

import java.util.Scanner;

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

全部评论

相关推荐

11-05 10:55
中南大学 Java
要双修的猫头鹰:这面试官怕不是个m
我来点评面试官
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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