即使条件不满足,如果语句始终在运行,也很奇怪

编程入门 行业动态 更新时间:2024-10-12 03:26:15
本文介绍了即使条件不满足,如果语句始终在运行,也很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对if语句有一个奇怪的问题.我正在检查布尔值是否为true,是否必须运行if语句.我在很多地方都使用System.out.println布尔值,其值始终为false,但if语句仍在运行.有帮助吗?

I have a strange problem with an if statement. I'm checking if a Boolean is true, if it is the if statement must run. I System.out.println the value of the boolean at a lot of places, its always false but the if statement still runs. Any help ?

import java.util.ArrayList; public class GameLoop extends Thread { private Boolean running; private ArrayList<Meteor> meteorArrayList; private Boolean win; private GameScreen gameScreen; public GameLoop(GameScreen gameScreen, ArrayList<Meteor> meteorArrayList) { setMeteorArrayList(meteorArrayList); setGameScreen(gameScreen); setRunning(true); setWin(false); } @Override public void run() { while (running) { if(checkWin()); { System.out.println(checkWin()); gameScreen.winGame(); } } } public Boolean checkWin() { if(getMeteorArrayList().isEmpty()) { setWin(true); } else { setWin(false); } System.out.println(getWin()); return getWin(); } public void cancel() { interrupt(); } //======================GETTER EN SETTERS============================= public Boolean getRunning() { return running; } public void setRunning(Boolean running) { this.running = running; } public ArrayList<Meteor> getMeteorArrayList() { return meteorArrayList; } public void setMeteorArrayList(ArrayList<Meteor> meteorArrayList) { this.meteorArrayList = meteorArrayList; } public Boolean getWin() { return win; } public void setWin(Boolean win) { this.win = win; } public GameScreen getGameScreen() { return gameScreen; } public void setGameScreen(GameScreen gameScreen) { this.gameScreen = gameScreen; }

}

推荐答案

在该行代码中有一个小的语法错误.

You have a small syntax error in that line of code.

代替

if (checkWin());

应该是

if (checkWin())

删除;

更多推荐

即使条件不满足,如果语句始终在运行,也很奇怪

本文发布于:2023-10-28 01:21:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535079.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也很   语句   不满足   奇怪   条件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!