1个回答
展开全部
public class Test11 {
public static void main(String[] args) {
final int N=7;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
if(k==1 || k==i || i==N)
System.out.print("* ");
else
System.out.print(" ");
}
System.out.println();
}
}
}
运行结果:
*
* *
* *
* *
* *
* *
* * * * * * *
public static void main(String[] args) {
final int N=7;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
if(k==1 || k==i || i==N)
System.out.print("* ");
else
System.out.print(" ");
}
System.out.println();
}
}
}
运行结果:
*
* *
* *
* *
* *
* *
* * * * * * *
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询