我正在使用 if 语句:
if(test == 1 || test == 2){
do something
}
我在 Java 中工作,不知何故,这段代码会产生“错误操作数类型”的错误。我知道它是 OR (||) 但我不知道如何解决它。代码:
public static int[] map =
//1 2 3 4 5 6 7 8 9 10
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //1
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //2
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //3
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //4
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //5
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //6
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //7
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //8
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //9
};
public static int mapRow, mapCol;
public static int mapRef = (mapRow + (mapCol * 10)) - 1;
String grass = "[ ] ";
String water = "{} ";
private int counter = 0;
void mapCreate(){
while(counter != 99){
if((counter = 0) || (counter = 10) || (counter = 20) || (counter = 30) || (counter = 40) || (counter = 50)
|| (counter = 60) || (counter = 70) || (counter = 80) || (counter = 90) || (counter = 100)){
if(map[counter] == 1){
System.out.println(grass);
} else if(map[counter] == 2){
System.out.println(water);
}
} else {
if(map[counter] == 1){
System.out.print(grass);
} else if(map[counter] == 2){
System.out.print(water);
}
}
counter++;
}
}
错误:
mapcreater.java:27: error: bad operand types for binary operator '||'
if((counter = 0) || (counter = 10) || (counter = 20) || (counter = 30) || (counter = 40) || (counter = 50)