在开关情况检查中,我具有以下Java(Android)代码。我已将默认条件设置为以下代码:
switch (value_gain_array[0]) {
case 5:
column[1][0] = "4";
column[1][1] = "3";
column[1][2] = "1";
break;
case 10:
column[1][0] = "4";
column[1][1] = "5";
column[1][2] = "1";
break;
case 50:
column[1][0] = "1";
column[1][1] = "1";
column[1][2] = "4";
break;
case 100:
column[1][0] = "2";
column[1][1] = "3";
column[1][2] = "5";
break;
case 500:
column[1][0] = "3";
column[1][1] = "2";
column[1][2] = "2";
break;
case 1000:
column[1][0] = "4";
column[1][1] = "4";
column[1][2] = "1";
break;
case 100000:
column[1][0] = "5";
column[1][1] = "5";
column[1][2] = "3";
break;
case 222:
column[1][0] = "4";
column[1][1] = "1";
column[1][2] = "1";
break;
case 999:
column[1][0] = "4";
column[1][1] = "2";
column[1][2] = "1";
break;
default:
boolean control = false;
while (control == false) {
//column[1][0] = Integer.toString(Generate_Random_15());
//column[1][1] = Integer.toString(Generate_Random_15());
//column[1][2] = Integer.toString(Generate_Random_15());
column[1][0] = "2";
column[1][1] = "3";
column[1][2] = "5";
String control_column = column[1][0] + column[1][1] + column[1][2];
if (!"431".equals(control_column) || !"451".equals(control_column) || !"114".equals(control_column) || !"235".equals(control_column) || !"322".equals(control_column) || !"441".equals(control_column) ||
!"553".equals(control_column) || !"411".equals(control_column) || !"421".equals(control_column)) { control = true;}
}
Toast.makeText(context, "control_column_0[]+ " + column[1][0]+column[1][1]+column[1][2], Toast.LENGTH_LONG).show();
break;
}
不幸的是,默认开关的if条件不起作用,即使我像下面的情况“ 235”一样强制将值控件设置为false,也永远不会发生。以下if条件应该创建一个无限循环(当然,真正的目的是使用随机生成器检查)我在做什么错了?
谢谢
皮埃尔
boolean control = false;
while (control == false) {
//column[1][0] = Integer.toString(Generate_Random_15());
//column[1][1] = Integer.toString(Generate_Random_15());
//column[1][2] = Integer.toString(Generate_Random_15());
column[1][0] = "2";
column[1][1] = "3";
column[1][2] = "5";
String control_column = column[1][0] + column[1][1] + column[1][2];
if (!"431".equals(control_column) || !"451".equals(control_column) || !"114".equals(control_column) || !"235".equals(control_column) || !"322".equals(control_column) || !"441".equals(control_column) ||
!"553".equals(control_column) || !"411".equals(control_column) || !"421".equals(control_column)) control = true;
}
Toast.makeText(context, "control_column_0[]+ " + column[1][0]+column[1][1]+column[1][2], Toast.LENGTH_LONG).show();
break;
}
答案 0 :(得分:2)
如果要将control
设置为值true
,如果控制号不是if条件中提到的任何值,则必须将这些值与逻辑AND连接:< / p>
if (!"431".equals(control_column) && !"451".equals(control_column) && !"114".equals(control_column) && !"235".equals(control_column) && !"322".equals(control_column) && !"441".equals(control_column) &&
!"553".equals(control_column) && !"411".equals(control_column) && !"421".equals(control_column)) control = true;