不好操作类型的二元运算符"&安培;" java的 [英] bad operand types for binary operator "&" java
本文介绍了不好操作类型的二元运算符"&安培;" java的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误显示了此行
if ((a[0] & 1 == 0) && (a[1] & 1== 0) && (a[2] & 1== 0)){
这是整个code:
public class Ex4 {
public static void main(String[] args) {
int [] a = new int [3];
if(args.length == 3)
{
try{
for(int i = 0; i < args.length; i++)
{
a[i] = Integer.parseInt(args[i]);
}
}
catch(NumberFormatException e){
System.out.println("Wrong Argument");
}
if ((a[0] & 1 == 0) && (a[1] & 1== 0) && (a[2] & 1== 0)){
System.out.println("yes");
}
else {
System.out.println("no");
}
}
else{
System.out.println("Error");
}
}
}
我已经解决了code:
I've fixed the code:
if ((a[0] & 1) == 0 && (a[1] & 1) == 0 && (a[2] & 1) == 0){
用托架的一个问题,更新的在未来的任何人。
Was an issue with the brackets, updated for anyone in the future.
推荐答案
==
比&放更高的优先级;
。您可能要在包装您的操作()
来指定自己的优先级。
==
has higher priority than &
. You might want to wrap your operations in ()
to specify your own priority.
((a[0] & 1) == 0)
同样,对于的如果
条件的所有部分。
这篇关于不好操作类型的二元运算符&QUOT;&安培;&QUOT; java的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文