I think my code is right but it prints out "Undefined Continent" not "Africa: Logos, Nigeria"


#1

public class Continents {
public static void main(String[] args){

int continent = 3;

switch(continent){
  case '1':System.out.println("North America: Mexico City, Mexico");
  break;
  case '2': System.out.println("South America: Sao Paulo, Brazil");
  break;
  case '3': System.out.println("Europe: Moscow, Russia");      
		break;
    
  case '4': System.out.println("Africa: Lagos, Nigeria");
  break;
  case '5': System.out.println("Asia: Shanghai, China");
  break;
  case '6': System.out.println("Australia: Sydney, Australia");
		break;
  case '7': System.out.println("Antarctica: McMurdo Station, US");
    break;
    default: System.out.println("Undefined Continent!");
    break;

}
}
}

Please help if you can


#2

'3' is the char. 3 is the int. This is not the same thing :slight_smile:

You should change all your cases to use integers (delete ' around the numbers).


#3

thank you so much...:slight_smile:


#4

You're very welcome :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.