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 trialKerin Chavarria
1,294 PointsJava code is not working in console, the previous codes which are the String variable come up first and the warn age not
I always try hard to find mistakes, but sometimes I get stuck and the problem I cannot resolve is that I have followed the teacher step by step, but for some reason that I do not know the previous codes
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__.
int age = 12;
if (age < 13) {
//Insert exit code
console.printf("Sorry you must be at least 13 to use this program.\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: ");
String adverb = console.readLine("Enter an adjective: ");
String verb = console.readLine("Enter a verb ending in -ing: ");
console.print("Your TreeStory:\n-----------------\n");
console.printf("%s is a %s %S.", name, adjective, noun);
console.printf("They are always %s %s.\n", adverb, verb);
}
}
1 Answer
andren
28,558 PointsTaking a quick glance at your code the only error that jumps out at me is in this line:
console.printf("%s is a %s %S.", name, adjective, noun);
You have capitalized the s in the third "%s", that is incorrect and will lead the program to crash. There might be other errors my quick glance did not catch, but try to fix that error first and see if the program runs properly.
Kerin Chavarria
1,294 PointsKerin Chavarria
1,294 Pointsthank you... I think I had it right but fix what you say and fix another mistake I made console.print("Your TreeStory:\n-----------------\n"); on this line method to print I didn't write console.printf hehe forgot the F I fix both and now it's working/ thank you so much!