java输出一个空心三角形A
时间: 2023-05-12 08:03:48 浏览: 89
java输出三角形
以下是Java输出一个空心三角形A的代码:
```
public class Main {
public static void main(String[] args) {
int n = 5;
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++) {
if (j == 1 || j == 2 * i - 1 || i == n) {
System.out.print("A");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
```
输出结果为:
```
A
A A
A A
A A
AAAAAAAAA
```
阅读全文