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

牛牛的字符菱形

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char ch = in.next().charAt(0);
        int n = 5;
        int centerX = n / 2;
        int centerY = n / 2;

        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                if(Math.abs(i - centerX) + Math.abs(j - centerY) <= n / 2) System.out.print(ch);
                else System.out.print(" ");
            }
            System.out.println();
        }
        
    }
}

曼哈顿距离解法 借鉴了这个博主https://blog.csdn.net/Weraphael/article/details/128595858

全部评论

相关推荐

07-20 11:20
新疆大学 Java
Alan_01:看到都是黑马点评跟苍穹外卖我就放心了
无实习如何秋招上岸
点赞 评论 收藏
分享
07-15 00:33
江苏大学 Java
代码飞升:哈哈哈哈评论区三个打广告的
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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