“Java Switch Anweisung” 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

Standardfall in Java Switch-Case

class Main {
  public static void main(String[] args) {
      int expression = 9;
        switch(expression) {
        
      case 2:
        System.out.println("Small Size");
        break;

      case 3:
        System.out.println("Large Size");
        break;
            
      // default case
      default:
        System.out.println("Unknown Size");
    }
  }
}
SAMER SAEID

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

Java Switch Anweisung

switch (expression) {

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

Java einschalten

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 Switch Anweisung”

Fragen ähnlich wie “Java Switch Anweisung”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen