dimanche 3 février 2019

Multiple conditions in if statement in JAVA problem

private String setDepartment (){
   int code = Integer.parseInt(JOptionPane.showInputDialog("Enter The Department Code:\n" +
            "1:Sales\n" +
            "2:Development\n" +
            "3:Accounting\n" +
           "4:None"));

    if (code !=1 || code !=2 || code !=3 || code !=4)

/*Why this if statement is always true? How do i solve it? */

{ JOptionPane.showMessageDialog(null, "Invalid Number.Enter a number between 1-4"); setDepartment(); }

    if (code==1){
        return "Sales";
    }
    else if (code==2){
        return "Development";
    }
    else if (code==3){
        return "Accounting";
    }
    else
        return "";
    }

Aucun commentaire:

Enregistrer un commentaire