Java Java Basics Perfecting the Prototype Reviewing Our Feedback

Java 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
andren
28,473 Points

Taking 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.

thank 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!