+ 1
Why it is not running?
public class Program { public static void main(String[] args) { String buttons = "buttons"; switch(buttons) { case 2, 5, 8 -> "button1"; case 5, 3, 9 -> "button2"; default -> "invalid buttons!"; }; } }
8 Respuestas
+ 1
The error is in String buttons first define buttons variable then pass in switch case statement
+ 3
It should be String buttons;
+ 2
Not
String buttons=" buttons";
+ 1
The issue is in String buttons first define buttons variable then pass in switch case
+ 1
Now also showing error
+ 1
You are passing string type value to switch but cases using of int type so not matches. Error
And you are not using or catching switch returned values so it can't output anything after removing error also. So print strings instead of just returning ... ( eg: "button 1" is incomplete statement)
@
also using 5 as dublicate values for cases..
Dublicate cases not allowed..
Hope it helps to correct it..
+ 1
Do you mean System. Out. Println("Button1");
0
Yes. Mayukh Banerjee that also valid. works...