输入样例:
5
输出样例:
*
***
*****
***
*
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int cx = n / 2, cy = n / 2;
for (int i = 0; i < n; i ++){
for (int j = 0; j < n; j ++){
int d = Math.abs(i - cx) + Math.abs(j - cy);
if (d <= n / 2)
System.out.printf("*");
else
System.out.printf(" ");
}
System.out.println();
}
}
}
标签:abs,Scanner,曼哈顿,距离,cx,int,cy,菱形,Math From: https://www.cnblogs.com/fghjktgbijn/p/17366809.html2023-05-01 18:15:17 星期一