Switch case in Java made simple with sample source code.

Pubblicato il: 12 dicembre 2021
sul canale di: Tech With Nate
32
2

Source Code
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the day");
String day = scanner.nextLine();

switch (day){
case "Sunday":
System.out.println("This is a resting day");
break;
case "Monday":
System.out.println("You have to report at work today");
break;
case "Tuesday":
System.out.println("You will have a meeting at your office");
break;
case "Wednesday":
System.out.println("Create schedule for the coming meeting");
break;
case "Thursday":
System.out.println("Go to dinner with Family");
break;
case "Friday":
System.out.println("Have a nap");
break;
case "Saturday":
System.out.println("Go to the laundry");
break;
default:
System.out.println("Not a day of the week");
break;

}


System.out.println("Enter a your choice" +
"\n\t1. Buy a data" +
"\n\t2. Check data balance" +
"\n\t3. Exit");

int choice = scanner.nextInt();

switch (choice){
case 1:
System.out.println("You are buying a data");
break;
case 2:
System.out.println("Checking data balance");
break;
case 3:
break;
default:
System.out.println("Invalid input");
break;
}


In questa pagina del sito puoi guardare il video online Switch case in Java made simple with sample source code. della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech With Nate 12 dicembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 32 volte e gli è piaciuto 2 spettatori. Buona visione!