What is the output: switch String value
public class Main { public static void main(String[] args) { String switchValue = "1"; switch (switchValue) { case "1": System.out.println("in case 1"); case "2": System.out.println("in case 2"); default: System.out.println("in default"); } } }
in case 1 in case 2 in default
public class Main { public static void main(String[] args) { String switchValue = "1"; switch (switchValue) { case "1": System.out.println("in case 1"); case "2": System.out.println("in case 2"); default://from w w w . j a v a2s. co m System.out.println("in default"); } } }
You can add break to jump out of case statement