public class ExOperator11 {
//(1)各定数に判定値の設置
static final int AGE = 1;
static final int ADDRESS = 2;
static final int SEX = 4;
static final int OTHERS = 8;
public static void main(String[] args) {
int judge = 0; //(2)
//(3)判定元変数と判定値のOR演算
judge = judge | AGE;
judge = judge | ADDRESS;
if ((judge & AGE) == AGE) { //(4)
if ((judge & ADDRESS) == ADDRESS) {
System.out.println("Your age and address is OK"); //(5)
} else {
System.out.println("Your address is NG");
}
} else {
System.out.println("Your age is NG");
}
}
}
|