How to use switch with multiple case values in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int n = 12;
         
        switch (n) {
            case 3:
            case 12:
            case 99:
                System.out.println("3 or 12 or 99");
                break; 
            case 7: 
                System.out.println("7"); 
                break; 
            default: 
                System.out.println("default"); 
        }
    }
}



/*
run:

3 or 12 or 99

*/

 



answered Apr 4, 2021 by avibootz

Related questions

1 answer 204 views
1 answer 156 views
1 answer 153 views
1 answer 192 views
192 views asked Nov 9, 2021 by avibootz
2 answers 235 views
...