我的 if 语句总是返回 true,无论如何 [英] My if statement ALWAYS returns true, no matter what
本文介绍了我的 if 语句总是返回 true,无论如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这对我来说根本没有意义.
This just is't making sense to me at all.
这是我的代码:
boolean that = false;
if (that == true);
{
System.out.println("That is " + that);
}
然而,即使我的输出是
That is false
我在 java 中执行此操作,并且使用 Eclipse galileo,因此每次编译/运行我的程序时,它都会保存它,因此编译器应该获得我程序的更新版本.怎么回事?
I'm doing this in java and I'm using Eclipse galileo, so each time I compile/run my program it saves it so the compiler should be getting updated version of my program. What's going on?
推荐答案
一个常见的错误.删除 if
语句末尾的 ;
.
A common mistake. Remove the ;
at the end of the if
statement.
顺便说一句,如果我使用括号并使用 IDE 的代码格式化程序,我总是会写以下内容.
BTW I always write the following if I use brackets and I use the code formatter of the IDE.
if (that == true) {
System.out.println("That is " + that);
}
这意味着如果你有一个错误放置的 ;
或 {
可能会更明显.
This means if you have a mis-placed ;
or {
it can be more obvious.
这篇关于我的 if 语句总是返回 true,无论如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文