import java.util.Scanner; public class 菱形 { public static void main(String[] args) { Scanner is_scanner = new Scanner(System.in); int hangshu = is_scanner.nextInt(); for (int m = 1; m <= hangshu; m++) { for (int i = 1; i <= hangshu - m; i++) { System.out.print(" "); } for (int s = 1; s <= 2 * m - 1; s++) { if (s == 1 || s == 2 * m - 1 ) { System.out.print("*"); } else { System.out.print(" "); }} System.out.println(); } for (int c = hangshu; c >= 1; c--) { for (int e = 1; e <= hangshu - c; e++) { System.out.print(" "); } for (int d = 1; d <= 2 * c - 1; d++) { if(d==1||d==(2*c-1)){ System.out.print("*");} else{ System.out.print(" ");} } System.out.println(); } }}
java 打印空心菱形
最新推荐文章于 2025-03-26 11:53:11 发布