Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlex Koo
317 PointsError : reached end of file while parsing
import java.io.Console;
public class TreeStory {
public static void main(String[] args) {
Console console = System.console();
/* Some terms:
noun - Person, place or thing
verb - An action
adjective - A description used to modify or describe a noun
Enter your amazing code here!
*/
String ageAsString = console.readLine("How old are you? ");
int age = Integer.parseInt(ageAsString);
if (age < 13) {
//Insert exit code
console.printf("Sorry you must be at least 13 to enter this pornhub. \n");
System.exit(0);
}
String name = console.readLine("Enter a name: ");
String adjective = console.readLine("Enter an adjective: ");
String noun = console.readLine("Enter a noun : ");
if (noun.equals("dork")) {
console.printf("not allowed. Exiting. \n\n");
System.exit(0);
}
Once I put those in, its keep saying
TreeStory.java:26: error: reached end of file while parsing } ^ 1 error.
Why is it keep saying that???? and also how to I copy and past the console?
1 Answer
Simon Coates
28,694 PointsEach { has to have a matching }. Correct indenting help line up each method/class/block opening ({) with each method/class/block ending (}). Assuming what you've posted is the complete code, you probably need to end with something like:
}
}
Alex Koo
317 PointsAlex Koo
317 PointsAfter Ive done what you said it still saying the same thing.... Ughhhhh any other ideas?
Simon Coates
28,694 PointsSimon Coates
28,694 PointsI tried using an online java sandbox. I had to change the class name as it was expecting a class called name. The following code:
produced:
So if you add the extra } symbols as suggested, save your changes and compile, then things should be okay.