“Java wechseln” Code-Antworten

Java -Schalter

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"
Worried Warbler

JavaScript -Switch

//javascript multiple case switch statement
var color = "yellow";
var darkOrLight="";
switch(color) {
    case "yellow":case "pink":case "orange":
        darkOrLight = "Light";
        break;
    case "blue":case "purple":case "brown":
        darkOrLight = "Dark";
        break;
    default:
        darkOrLight = "Unknown";
}

//darkOrLight="Light"
Grepper

Ausdruck Java wechseln

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);
        }
    );
Minecraftian14

Syntax der Switch -Anweisung in Java

switch (expression) {

  case value1:
    // code
    break;
  
  case value2:
    // code
    break;
  
  ...
  ...
  
  default:
    // default statements
  }
rono schngr

Java wechseln

int x = 5;
switch(x) {
case 1:
    System.out.println("You entered 1");
    break;
case 2:
    System.out.println("You entered 2");
    break;
default:
    System.out.println("You entered: "+x);
}	
The Cat Coder

So verwenden Sie eine Switch -Anweisung in Java

case 6:
    System.out.println("Today is Saturday");
    break;
  case 7:
Fantastic Flatworm

Ähnliche Antworten wie “Java wechseln”

Fragen ähnlich wie “Java wechseln”

Weitere verwandte Antworten zu “Java wechseln” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen