Help Please


public class Continents {
public static void main(String[] args) {
int continent = 4;

case 1: System.out.println("North America: Mecico City, Mexico");

  case 2: System.out.println("South America: Sao Paulo, Brazil");

    case 3: System.out.println("Europe: Moscow, Russia");

case 4: System.out.println("Africa: Lagos, Nigeria");

case 5: System.out.println("Asia: Shanghai, China");

  case 6: System.out.println("Australia: Sydney, Australia");

case 7: System.out.println("Anatartica: McMurdo Station, US");

default: System.out.println("Undefined continent!");


Message Result:
Africa: Lagos, Nigeria
Asia: Shanghai, China
Australia: Sydney, Australia
Anatartica: McMurdo Station, US
Undefined continent!


You're missing break; after every case. Right now, it goes to case 4, and then since there is no break it runs through every single case after 4, printing all the values you see. Add a break statement after every case and you'll be fine:

case 1: System.out.println("North America: Mexico City, Mexico");
case 2: ...


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