dimanche 21 juillet 2019

Is the switch statement compatible with the if statement?

Is it possible to use the switch statement inside a switch case and if not so can some one explain?

int result = year + month;


if ((month <= 1 || month > 12) || (year < 1 || year > 9999)) {
    switch (month) {
    case 1:
        System.out.Println("This month is January");
        break;

    default:
        throw new IllegalArgumentException("Unexpected value: " + key);
    }
}
else {return -1;}

Aucun commentaire:

Enregistrer un commentaire