mardi 6 octobre 2020

Convert the following switch statement into if-else statements:

int month = input.nextInt();
switch (month) { 
    case 1:
        System.out.println(“January”);
    case 2:
        System.out.println(“February”); break;
    case 3:
        System.out.println(“March”); break;
    case 4:
        System.out.println(“April”);
    case 5:
        System.out.println(“May”); break;
    default:
        System.out.println(“Invalid”); break;
}

How do I convert it from switch statement into if-else statment?

the breaks are intentional, this is a college assignment.

Aucun commentaire:

Enregistrer un commentaire