package de;
public class jinZhiTan {
public static void main(String[] args) {
int lay = 7;
for(int i=1;i<=lay;i++){
for(int k=1;k<=lay-i;k++){
System.out.println(" ");
}
for(int j=1;j<=2*i-1;j++){
System.out.println("*");
}
System.out.println();
}
}
}
public static void main(String[] args) {
int lay = 7;
for(int i=1;i<=lay;i++){
for(int k=1;k<=lay-i;k++){
System.out.print(" ");
}
for(int j=1;j<=2*i-1;j++){
System.out.print("*");
}
System.out.println();
}
}
println结尾自带换行
你控制换行的那个循环写错了。
int i = 5;
for (int j = 1; j <= i; j++) {
int times = (2*j)-1;
int time=0;
while(time!=(i-j))
{
System.out.print(" ");
time++;
}
while (times != 0) {
System.out.print("*");
times--;
}
System.out.print("\n");