展开全部
打印空心菱形的Java程序如下:
public class Test6 {
public static void main(String[] args) {
final int N=5;
for (int i = 1; i <= N*2-1; i++) {
for (int j = 1; j <= Math.abs(N - i); j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2*N-1-Math.abs(i-N)*2; k++) {
if(k==1 || k == 2*N-1-Math.abs(i-N)*2)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
运行结果:
*
* *
* *
* *
* *
* *
* *
* *
*
public class Test6 {
public static void main(String[] args) {
final int N=5;
for (int i = 1; i <= N*2-1; i++) {
for (int j = 1; j <= Math.abs(N - i); j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2*N-1-Math.abs(i-N)*2; k++) {
if(k==1 || k == 2*N-1-Math.abs(i-N)*2)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
}
}
运行结果:
*
* *
* *
* *
* *
* *
* *
* *
*
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询