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
Amulya Arora
6,133 Pointswhat should i do???
this is the code:- 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<10) {
//exit code
console.printf("sorry you must be 10 to use this program./n");
System.exit(0);
}
String name= console.readLine("Enter your name: ");
String adjective=console.readLine("Enter your adjective: ");
String noun;
boolean isInvalidWord;
do{
noun= console.readLine("Enter your noun: ");
isInvalidWord = (noun.equalsIgnoreCase("dork") ||
noun.equalsIgnoreCase("jerk"));
if (isInvalidWord) {
console.printf("Sorry, this language is not acceptable.Try again. \n\n");
} while (inValidWord);
console.printf("%s is very %s and %s", name, adjective, noun);
}
}
}
this is the problem:-
TreeStory.java:32: error: while expected
}
^
TreeStory.java:34: error: illegal start of expression
}
^
TreeStory.java:34: error: reached end of file while parsing
}
^
TreeStory.java:35: error: reached end of file while parsing
^
please tell me what to do
1 Answer
Krishna Pratap Chouhan
15,203 PointsI have couple of questions:
misplaced while in #"do-while"
if (isInvalidWord) {
console.printf("Sorry, this language is not acceptable.Try again. \n\n");
}} while (inValidWord); //---------------------------------->here
console.println("%s is very %s and %s", name, adjective, noun);
}
Where did you closed your class:
console.println("%s is very %s and %s", name, adjective, noun);
}
//Missing one more parenthesis
Lastly, there are some undeclared variable.
if (isInvalidWord) {
console.printf("Sorry, this language is not acceptable.Try again. \n\n");
}} while (inValidWord); //---------------------check your code here
console.println("%s is very %s and %s", name, adjective, noun);
}
Oh! also problem in #\n <=> /n
//exit code
console.printf("sorry you must be 10 to use this program.\n"); //--------------------->here
System.exit(0);
Final Code:
public class treestory {
public static void main(String[] args) {
Console console = System.console();
String ageAsString= console.readLine("How old are you?: ");
int age= Integer.parseInt(ageAsString);
if(age<10) {
//exit code
console.printf("sorry you must be 10 to use this program.\n");
System.exit(0);
}
String name= console.readLine("Enter your name: ");
String adjective=console.readLine("Enter your adjective: ");
String noun;
boolean isInvalidWord;
do{
noun= console.readLine("Enter your noun: ");
isInvalidWord = (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"));
if (isInvalidWord) {
console.printf("Sorry, this language is not acceptable.Try again. \n\n");
}
} while (inValidWord);
console.println("%s is very %s and %s", name, adjective, noun);
}
}
Amulya Arora
6,133 PointsAmulya Arora
6,133 PointsThanks a Lot!