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 trialMonica Wilson
293 PointsMy workspace never displays, "How old are you ?". I get several errors although I typed everything exactly the same as C
My workspace never displays, "How old are you ?". I get several errors although I typed everything exactly the same as Craig. How can I reset my workspace back to the default before what I recently saved? I may have deleted important code.
10 Answers
Lauren Moineau
9,483 PointsThank you. You are indeed missing a closing bracket.
You should have:
- a closing bracket for the if block
- a closing bracket for the main method
- a closing bracket for the class
You were actually missing 2 previously. My bad, I only saw 1 missing. I edited my previous answer. Just add a closing bracket and you will be fine :)
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!
*/
// __Name__ is a __adjective__ __noun__. They are always __adverb__ __verb__.
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 use this program.\n");
System.exit(0);
} // <- closing bracket for the if block
} // <- closing bracket for the main method
} // <- closing bracket for the class
Monica Wilson
293 PointsMonica Wilson
293 Pointsscreen shot your code please
Lauren Moineau
9,483 PointsI edited my previous post
Lauren Moineau
9,483 PointsHi Monica. You have 2 options:
- Go to Workspaces on the right of the Treehouse top menu bar up there ^ (next to your points) and delete the workspace from the list. Then re-create a brand new one from the lesson.
- Post your code here so we can help you find where the error is.
Hope that helps :)
Monica Wilson
293 Pointsimport 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!
*/
// __Name__ is a __adjective__ __noun__. They are always __adverb__ __verb__.
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 use this program.\n");
System.exit(0);
}
}
Same error:
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:22: error: reached end of file while parsing
}
^
1 error
Lauren Moineau
9,483 PointsHi Monica. It looks like you're just missing the closing bracket for your if block:
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!
*/
// __Name__ is a __adjective__ __noun__. They are always __adverb__ __verb__.
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 use this program.\n");
System.exit(0);
} // <- Add this missing bracket
}
Hope that helps:)
Edit: 2 closing brackets were actually missing
Monica Wilson
293 Pointssame error:
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:22: error: reached end of file while parsing
}
^
1 error
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!
*/
// __Name__ is a __adjective__ __noun__. They are always __adverb__ __verb__.
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 use this program.\n");
System.exit(0);
}
}
Monica Wilson
293 Pointsit doesn't show both brackets inside the cmd prompt screen but it is there
Lauren Moineau
9,483 PointsHi. It is not there in the code you pasted above.
Monica Wilson
293 Pointsi have a screen shot. it is. not sure why it doesn't show
Lauren Moineau
9,483 PointsYou need 2 closing brackets after
System.exit(0);
One for the if block and one for the main method, as in the code I included in my previous answer.
Monica Wilson
293 PointsAre you able to access my forked ws?
Lauren Moineau
9,483 PointsYes, just post the link here. I'll have a look
Monica Wilson
293 Pointsit worked!!!! thanks
Lauren Moineau
9,483 PointsYou're welcome! Glad it's sorted :)
Monica Wilson
293 PointsThanks so much for helping me through this! I'm learning tons
Lauren Moineau
9,483 PointsNo problem. I'm glad you're enjoying this. Happy coding! :)