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

Java Java Basics Using your New Tools Coding the Prototype

Raymond Pride
PLUS
Raymond Pride
Courses Plus Student 4,938 Points

I'm not sure why but my code will not read. Can anyone help?

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 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 adverb:  ");
 String verb = console.readLine("Enter a verb ending with -ing:  ");

  console.printf("Your TreeStory:\n----------\n");
  console.printf(%s is a %s %s. ", name, adjective, noun);
                 console printf(They are always %s %s.\n", adverb, verb);
}

}

this is the result

TreeStory.java:6: error: ';' expected
Console console System.console();
^
1 error
treehouse:~/workspace$

Also all of the equal signs in the strings above are red on my screen not green

3 Answers

In my workspace this code ran perfect.

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 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 adverb:  ");
      String verb = console.readLine("Enter a verb ending with -ing:  ");
      console.printf("Your TreeStory: \n---------------------\n");
      console.printf("%s is a %s %s.", name, adjective, noun);
      console.printf("They are always %s %s.\n", adverb, verb);
    }

}
Daniel Hartin
Daniel Hartin
18,106 Points

Hi Raymond

It looks like a simple typo, shame the compiler has given you a very cryptic error message (it does this sometimes). It looks to me like you're simply missing an equals sign on the first line in the main method. The code below is corrected.

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 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 adverb:  ");
 String verb = console.readLine("Enter a verb ending with -ing:  ");

  console.printf("Your TreeStory:\n----------\n");
  console.printf("%s is a %s %s. ", name, adjective, noun);
  console.printf("They are always %s %s.\n", adverb, verb);
}

Hope this helps

Daniel

Raymond Pride
Raymond Pride
Courses Plus Student 4,938 Points

I copied your answer into the worksheet but still the same result

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 alwaysadverb verb.// 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 adverb: "); String verb = console.readLine("Enter a verb ending with -ing: ");

console.printf("Your TreeStory:\n----------\n"); console.printf(%s is a %s %s. ", name, adjective, noun); console printf(They are always %s %s.\n", adverb, verb); }

this is the result again

TreeStory.java:6: error: ';' expected Console console System.console(); ^ 1 error

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Raymond

Sorry, I think I missed something... the last 2 line were muddled with the speech marks. I have compiled and tested the below in workspaces and all is well :)

import java.io.Console;

public class Introductions {

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 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 adverb:  ");
 String verb = console.readLine("Enter a verb ending with -ing:  ");

  console.printf("Your TreeStory:\n----------\n");
  console.printf("%s is a %s %s. ", name, adjective, noun);
  console.printf("They are always %s %s.\n", adverb, verb);
  }
}
Raymond Pride
Raymond Pride
Courses Plus Student 4,938 Points
import java.io.Console;

public class Introductions {

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 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 adverb: "); 
String verb = console.readLine("Enter a verb ending with -ing: ");

console.printf("Your TreeStory:\n----------\n"); 
console.printf("%s is a %s %s. ", name, adjective, noun); 
console.printf("They are always %s %s.\n", adverb, verb); 
} 
}

TreeStory.java:6: error: ';' expected
Console console System.console();
^
1 error

Still the same error. Maybe something is wrong with my workspace client?

Daniel Hartin
Daniel Hartin
18,106 Points

Alright Raymond

Just to make sure, when you paste the corrected code I've posted into workspaces are you saving the changes and then recompiling the code using

clear && javac Introductions.java && java Introductions

in the console window of workspaces? it's just I have compiled and run that code perfectly and I want to rule out some other possibilities first.

Craig Drummond
Craig Drummond
933 Points

In your first printf line, your forgot the first quotation mark, just before the %s: console.printf(%s is a %s %s. ", name, adjective, noun); Should read: console.printf("%s is a %s %s. ", name, adjective, noun);

For the second printf statement, you are missing a period between console and printf: console printf(They are always %s %s.\n", adverb, verb); Should read: console.printf(They are always %s %s.\n", adverb, verb);

This could also be why you're generating these errors.