thePlayer.positio-6ren">
gpt4 book ai didi

java - 当与 if 语句相同时给出 "Found one too many { characters without a } to match it"

转载 作者:行者123 更新时间:2023-12-01 23:06:37 25 4
gpt4 key购买 nike

当运行以下代码时,它不会编译,并且收到一条错误消息,“发现一个太多的 { 字符,没有 } 与之匹配。”。

while (thePlayer.position.x > thePlayer.position2.x - 60) { 
println("x2 =" + thePlayer.position2.x);
thePlayer.position.x = thePlayer.position.x - 1;
println("x =" + thePlayer.position.x);
}
else {
thePlayer.position2.x = thePlayer.position.x;
println("complete");
}

但是,当我将其更改为下面的示例(if 语句)时,它可以正常编译并运行,唯一的更改是将“while”替换为“if”。

if (thePlayer.position.x > thePlayer.position2.x - 60) { 
println("x2 =" + thePlayer.position2.x);
thePlayer.position.x = thePlayer.position.x - 1;
println("x =" + thePlayer.position.x);
}
else {
thePlayer.position2.x = thePlayer.position.x;
println("complete");
}

我真的很困惑......

最佳答案

如果没有 if 语句,就不能有 else 语句。变化:

while (thePlayer.position.x > thePlayer.position2.x - 60) { 
println("x2 =" + thePlayer.position2.x);
thePlayer.position.x = thePlayer.position.x - 1;
println("x =" + thePlayer.position.x);
}
else {
thePlayer.position2.x = thePlayer.position.x;
println("complete");
}

至:

while (thePlayer.position.x > thePlayer.position2.x - 60) {
println("x2 =" + thePlayer.position2.x);
thePlayer.position.x = thePlayer.position.x - 1;
println("x =" + thePlayer.position.x);
}

thePlayer.position2.x = thePlayer.position.x;
println("complete");

这将运行循环,当条件变为 false 时,它​​将运行 while 循环之后的行。

关于java - 当与 if 语句相同时给出 "Found one too many { characters without a } to match it",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22649774/

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