“sakelar java” Kode Jawaban

sakelar java

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

Beralih Java Ekspresi

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

Sintaks pernyataan sakelar di java

switch (expression) {

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

Beralih di Java

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

cara menggunakan pernyataan sakelar di java

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

Jawaban yang mirip dengan “sakelar java”

Pertanyaan yang mirip dengan “sakelar java”

Lebih banyak jawaban terkait untuk “sakelar java” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya