“Pernyataan 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

Kasing default di 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

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

Pernyataan sakelar 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 “Pernyataan sakelar Java”

Pertanyaan yang mirip dengan “Pernyataan sakelar Java”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya