mardi 4 décembre 2018

Java - Operator does not equal not working in a if condition for strings

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;
    }

Aucun commentaire:

Enregistrer un commentaire