私は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)