我创建了一个枚举wearState,然后将wearState作为两个变量的类型。但是当我尝试用“||”将它们置于 if 条件时 或“&&”,它不起作用。它说:“错误:二元运算符‘||’的操作数类型错误 ”enum wearState { WRIST_MOVE, WRIST_IMMOBILE, BELT_NECK_MOVE, BELT_NECK_IMMOBILE, OTHER_IMMOBILE_STATE; }enum chargingState { YES, NO, }wearState lastState;wearState currentState;chargingState lastStateCharging;chargingState currentStateCharging;if (((currentState = wearState.BELT_NECK_IMMOBILE) || (currentState = wearState.WRIST_IMMOBILE)) && (lastStateCharging = chargingState.NO)) { /* .... */ }
1 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
if (((currentState == wearState.BELT_NECK_IMMOBILE) || (currentState == wearState.WRIST_IMMOBILE)) && (lastStateCharging == chargingState.NO))
比较两个变量是否请使用“==”,=是赋值运算符。它只能用于为变量赋值,例如,
String name="Joe";
为了与变量进行比较,我们应该使用比较运算符。==、<=、>=、!=、<、> 是比较运算符;
添加回答
举报
0/150
提交
取消