Countries and Cities - Issues with break statement


#1

I can’t figure out what the problem is here. When I run the code I wrote I receive this error “Continents.java:11: error: class, interface, or enum expected”

My code is as follows:

note when I include a “;” my error rate doubles.

public string: Continent {
public switch string void main(String[] args)
{

int Continent = 4
switch = continentString
switch (continent)
{

case ‘1’: System.out.println(“North Amrica: Mexico City, Mexico”);
break
case ‘2’: System.out.println(“South Amrica: 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(“Undefind Continent”);
break
}
}
}


#2

I deleted all the “;” and I only having an issue with the first two lines:

public String: Continent {
public switch string void main (String [] args)
{

int Continent = 4
switch = continentString
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(“Undefind Continent”)
break
}
}
}


#3

Please furnish a link to the exact exercise. Thanks.

Are you getting any error messages?


#4

https://www.codecademy.com/en/courses/learn-java/projects/continents-cities

Yes, for lines 1 & 2:

Continents.java:1: error: class, interface, or enum expected
public String Continent {
^
Continents.java:2: error: class, interface, or enum expected
public switch string void main (String [ ] args)
^
2 errors


public String Continent {
public switch string void main (String [ ] args)
{

int Continent = 4
switch = continentString
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(“Undefind Continent”)
break
}
}
}


#5

Did you mean to write,

public class Continents

Did you mean to write,

public static void main(String[] args)

That line doesn’t make much sense. It could be overwriting the switch method. I would say remove it.


#6

Thanks for the above, now I’m only receiving one error message: “Could not find or load main class Continents”

class Continent {
static void main (String [] args)
{

int Continent = 4;
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(“Undefind Continent”);
break;
}
}
}


#7

Those are both missing public at the beginning.


#8

Thanks for the help!


#9

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