+ 1
why default case is not working. i would appreciate any help.
switch(y){ case "India": write(); break; case "France": write_q(); break; case default: System.out.print("no idea"); break; } }public static void write(){ System.out.print("Asia") ; } public static void write_q(){ System.out.print("Europe") ; } }
6 Respuestas
+ 4
you have "case default:", replace that with "default:". You do not need the case in front of default.
+ 2
i m using code playground so is it due to the software or codes
+ 1
Code Playground is currently using Java version 1.8.0_65 or Java 8 update 65. So the use of a string in a switch shouldn't be an issue here. So there must be something else going on with your code that is not shown in the sample you provided.
+ 1
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner w = new Scanner(System.in);
String y = w.next();
remaining codes is this
0
Which version of the JDK are you using? If it's Java 6 or older you can't switch on a string. Java 7 or newer should work fine. Given that in the code you presented we don't know the value of y nor can we see the actual implementation of your code it's very difficult to give an appropriate answer other than this. From what is here it appears that there is an extra closing curly brace after the switch statement.
0
@David
good catch don't know how i missed that. lol