java代码中的判断语句

来源:百度知道 编辑:UC知道 时间:2024/07/04 20:41:12
if (item.getName().equals("trainYear") && item.getValue().equals("1") && item.getName().equals("trainCity") && item.getValue().equals("0"))

这个语句可以先后顺序是怎么样的?

我想要这样:

if [(item.getName().equals("trainYear") && item.getValue().equals("1") ]&& [item.getName().equals("trainCity") && item.getValue().equals("0")) ]

语句要怎么改呢?

if ((item.getName().equals("trainYear") && item.getValue().equals("1"))&& (item.getName().equals("trainCity") && item.getValue().equals("0")) )

if(item.getName().equals("trainYear") && item.getValue().equals("1")){
if(item.getName().equals("trainCity") && item.getValue().equals("0")){
//code
}
}

只有 && 一种运算符 执行顺序也就是从前一直向后的,你可以用小括号实现你的顺序,把你的下面那句中[] 改为 ()即可