Answers for "switch case syntax java"

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
2

java switch

//the cooler looking edition (with input example)
Scanner scn = new Scanner(System.in);
int asd = scn.nextInt();

switch(asd)
{
  case 1 -> System.out.println("case 1");
  case 2 -> System.out.println("case 2");
  case 5 -> System.out.println("case 5");
  //case n...
  default -> case 1 -> System.out.println("check out tunalad.bandcamp.com");
}

/* Output:
asd = 1: "case 1"
asd = 2: "case 2"
asd = 5: "case 5"
asd = 33213: "check out tunalad.bandcamp.com"
*/
Posted by: Guest on July-10-2021
1

java switch tutorial

For details about Java Switch tutorial visit website:
https://www.allaboutjava.com/2021/07/java-switch-statements.html
Posted by: Guest on July-21-2021
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