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 trial
Dov Brodkin
2,695 PointsJava : reached end of file while parsing error, can't get my code to run.
My code will not run, not sure why. Can anyone help? (Java)
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 ageString = console.readLine("How old are you? \n");
int age = Integer.parseInt(ageString);
if (age < 13) {
console.printf("Sorry you are not old (or awesome) enough to use this epic pg-13 madlib.\n");
System.exit(0);
}
String personOne;
do {
personOne = console.readLine("Enter a person's name:\n");
if (personOne.equalsIgnoreCase("Hillary") ||
personOne.equalsIgnoreCase("Clinton")){
console.printf("That person is not allowed on here.\nTry Again.\n");
} while(personOne.equalsIgnoreCase("Hillary") ||
personOne.equalsIgnoreCase("Clinton"));
String country = console.readLine("Name a country:\n");
String personTwo = console.readLine("Name a person:\n");
String adverbOne = console.readLine("Name a adverb ending with ly:\n");
String verb = console.readLine("Mode of transportation in verb form:\n");
console.printf("One day %s was walking in %s, when he ran into %s. He said to him get out of my way. %s he %s away.\n", personOne, country, personTwo, adverbOne, verb);
}
5 Answers
Simon Coates
28,695 Pointsif statement not closed:
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 ageString = console.readLine("How old are you? \n");
int age = Integer.parseInt(ageString);
if (age < 13) {
console.printf("Sorry you are not old (or awesome) enough to use this epic pg-13 madlib.\n");
System.exit(0);
}
String personOne;
do {
personOne = console.readLine("Enter a person's name:\n");
if (personOne.equalsIgnoreCase("Hillary") ||
personOne.equalsIgnoreCase("Clinton")){
console.printf("That person is not allowed on here.\nTry Again.\n");
}//added
} while(personOne.equalsIgnoreCase("Hillary") || personOne.equalsIgnoreCase("Clinton"));
String country = console.readLine("Name a country:\n");
String personTwo = console.readLine("Name a person:\n");
String adverbOne = console.readLine("Name a adverb ending with ly:\n");
String verb = console.readLine("Mode of transportation in verb form:\n");
console.printf("One day %s was walking in %s, when he ran into %s. He said to him get out of my way. %s he %s away.\n", personOne, country, personTwo, adverbOne, verb);
}
}
indenting helps see how { and } are meant to match up.
Simon Coates
28,695 Pointstends to mean you're missing at least one } at the end of the file.
Jason Anders
Treehouse Moderator 145,863 PointsAdded markdown to your code for readability in the forum (Please refer to the Markdown CheatSheet)
Simon is correct, you are missing the closing brace for the Class.
Dov Brodkin
2,695 PointsWhere do I put it, I tried doing that, and got the same error.
Dov Brodkin
2,695 PointsIt also says (in terms of a second error. Error: while expected } undercarrot.
Dov Brodkin
2,695 PointsWhat do you mean, they both have both brackets.
Simon Coates
28,695 Pointsin my code, I added a }. It closes the if. Without it the } that follows was regarded as part of the if, not part of the do while.
Dov Brodkin
2,695 PointsThank you so much.
Dov Brodkin
2,695 PointsDov Brodkin
2,695 PointsDo they need semicolons
Simon Coates
28,695 PointsSimon Coates
28,695 Pointsdoes what need semicolons?