[Java] 纯文本查看 复制代码
package HW1221;
import java.util.Scanner;
public class rhombus {
public static void main(String[] args) {
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入三角形的行数");
int K = scanner.nextInt();
int i;
int j;
// 上半部分
//空格循环
for (i = 0; i < K; i++) {
for (j = i + 1; j < K; j++) {
System.out.print(" ");
}
for (j = 0; j < (i + 1) * 2 - 1; j++) {
System.out.print(" *");
}
System.out.println();
} //下半部分
for (i = 0; i < K - 1; i++) {
for (j = 0; j <= i; j++) {
System.out.print(" ");
}
for (j = 0; j <2*(K-3)-2*i+3; j++) {
System.out.print(" *");
}
System.out.println();
}
}
}
}