java输出一个实心菱形
时间: 2024-05-08 10:20:20 浏览: 77
Java输出一个实心菱形算法
好的,以下是Java代码实现输出一个实心菱形的图案:
```
import java.util.Scanner;
public class PrintRhombus {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i <= n; i++) {
for (int j = 0; j < n - i; j++) {
System.out.print(" ");
}
for (int k = 0; k < i; k++) {
System.out.print("* ");
}
System.out.println();
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j < n - i; j++) {
System.out.print(" ");
}
for (int k = 0; k < i; k++) {
System.out.print("* ");
}
System.out.println();
}
}
}
```
运行程序后,会提示你输入菱形的行数(必须是奇数),然后程序会输出对应行数的实心菱形图案。希望能解决你的问题!
阅读全文