Answers for "switch case in javas"

161

js switch case

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Posted by: Guest on February-21-2020
83

java switch

int day = 4;
switch (day) {
  case 6:
    System.out.println("Today is Saturday");
    break;
  case 7:
    System.out.println("Today is Sunday");
    break;
  default:
    System.out.println("Looking forward to the Weekend");
}
// Outputs "Looking forward to the Weekend"
Posted by: Guest on March-11-2020
11

switch case in javascript

function whatToDrink(time){
    var drink ;
          switch (time) {
            case "morning":
              drink = "Tea";
              break;
            case "evening":
              drink = "Shake";
              break;
            default:
              drink="Water";   
          }
  	return drink;
}
console.log(whatToDrink("morning")) //Tea
console.log(whatToDrink("evening")) //Shake
console.log(whatToDrink("night"))   //Water
console.log(whatToDrink("daytime")) //Water
Posted by: Guest on September-01-2020
1

switch statement in java

// syntax of switch statement in java
switch(expression)
{
   case 1 value :
   // code goes here
   break;

   case 2 value :
   // code goes here
   break;

   case 3 value :
   // code goes here
   break;
   .
   .
   .
   .
   
   default: // optional
   // default code goes here
}
Posted by: Guest on November-25-2020
0

switch expression java

System.out.println(
        switch (day) {
            case MONDAY, FRIDAY, SUNDAY -> 6;
            case TUESDAY                -> 7;
            case THURSDAY, SATURDAY     -> 8;
            case WEDNESDAY              -> 9;
            default -> throw new IllegalStateException("Invalid day: " + day);
        }
    );
Posted by: Guest on September-30-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language