gpt4 book ai didi

java - 没有进入for循环

转载 作者:行者123 更新时间:2023-11-30 07:11:31 27 4
gpt4 key购买 nike

我仍在研究我的 Java 菱形继承(钻石问题)。

这是钻石的当前状态

http://prntscr.com/2i9l9y

我认为问题出在 for 循环上,我只需要打印这些空格,然后我就完成了。

谁能看出我标记为问题的 for 循环没有被输入或运行的任何明显原因?

//Bottom half of the diamond

int middleSpaces = sides + 2;
int downPreSpaces = 1;
int dRows = sides + 1;

for (int x = 1; x <= dRows; x++) {
if (x >= dRows) {
for (int z = 1; z <= sides + 1; z++) {
System.out.print(" ");
}
System.out.print("v");
}

if (x != dRows) {

for(int y = 1; y <= x; y++) {
System.out.print(" ");
}

System.out.print("\\");

//PROBLEM IS HERE

for (int e = middleSpaces - 2; e <= 0; e += 2) {
System.out.print(" ");
}

System.out.print("/\n");
}

最佳答案

使用调试器单步执行您的代码,并在导致问题的位置检查变量 e 和 dRows 的状态。

关于java - 没有进入for循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21056710/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com