I have the following code for Java (Android) in a switch case check. I have set the default condition to the following code:
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;
}
Unfortunatly the if condition of the default switch is not working, even when I force the value control to be false like in the following case "235", it never happens. The following if condition should create an infinite loop (of course, the real purpose is to use random generator check instead) What am I doing wrong ?
Thank you,
Pierre
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;
}
-
Not sure if i understand your problem. Do you want control to be true, if you have 235 or not?dunni– dunni2018年12月04日 18:19:53 +00:00Commented Dec 4, 2018 at 18:19
-
No, I want control to be false if 235PGibouin– PGibouin2018年12月04日 18:22:40 +00:00Commented Dec 4, 2018 at 18:22
-
So if control has the value of one of the strings in that if, it should be false, otherwise it should be true, right?dunni– dunni2018年12月04日 18:25:19 +00:00Commented Dec 4, 2018 at 18:25
-
The purpose of the default condition is to generate random numbers which are NOT 431 451 114 235 322 etcPGibouin– PGibouin2018年12月04日 18:25:54 +00:00Commented Dec 4, 2018 at 18:25
-
Yes, exactly dunniPGibouin– PGibouin2018年12月04日 18:27:19 +00:00Commented Dec 4, 2018 at 18:27
1 Answer 1
If you want to set control to the value true, if the control number is not any of the values mentioned in your if condition, you have to connect the values with the logical AND:
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;
Comments
Explore related questions
See similar questions with these tags.