gpt4 book ai didi

java - For循环关闭/退出应用程序

转载 作者:行者123 更新时间:2023-12-01 21:59:20 25 4
gpt4 key购买 nike

当棋盘上的所有图 block 都 == 为 null 时,此代码应该关闭应用程序,但目前,当循环运行时,一旦发现只有 1 个图 block 为 null,它就会退出应用程序。我该如何解决这个问题?

谢谢!

public void close(){
for (int row = 0; row < 4; row++){
for (int col = 0; col < 4; col++){
if (tiles[row][col] == null) {
System.exit(0);
}
}
}
}

最佳答案

因为你的逻辑是错误的。它应该像下面这样。

public void close(){
for (int row = 0; row < 4; row++){
for (int col = 0; col < 4; col++){
if (tiles[row][col] != null) {
return; // leave this function and don't exit for any non-null tile
}
}
}
System.exit(0);
}

关于java - For循环关闭/退出应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33844904/

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