java要求用for语句输出数字金字塔: 1 131 135731 135797531
1个回答
展开全部
class Test {
public static void main(String[] args) {
for (int h = 1; h <= 5; h++) {
for (int k = 0; k < 5 - h; k++)
System.out.print(" ");
for (int x = 0; x < h; x++) {
System.out.print(x * 2 + 1);
}
for (int x = h - 1; x > 0; x--) {
System.out.print(x * 2 - 1);
}
System.out.println();
}
}
}
public static void main(String[] args) {
for (int h = 1; h <= 5; h++) {
for (int k = 0; k < 5 - h; k++)
System.out.print(" ");
for (int x = 0; x < h; x++) {
System.out.print(x * 2 + 1);
}
for (int x = h - 1; x > 0; x--) {
System.out.print(x * 2 - 1);
}
System.out.println();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询