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 Perfecting the Prototype Looping until the value passes

Samuel Furr
Samuel Furr
4,893 Points

What are the methods for the console object?

It's asking me to prompt for input from the user, but its been a few days since ive done an exercise, and I cant remember what the method is that I can call to get the response. What is it?

1 Answer

The method you're thinking of is the 'readLine();' method, and you invoke it off of a console object.

If you wanna read more about the Console class(which will give you detailed info about the other methods offered from the Console class can be read here: https://docs.oracle.com/javase/7/docs/api/java/io/Console.html

I'm not sure if there were any changes made, I doubt there were, but just in case. Here's a link to the Console docs for Java SE8. (The first link is the to the Java SE7 Console class docs): https://docs.oracle.com/javase/8/docs/api/java/io/Console.html

import java.io.Console;

public class ConsolePractice {
    public static String name;
    static Console console = System.console();

    public static void main(String[] args) {
        name = console.readLine("What is your name?: ");  //readLine(); prompts for the user input,
                                                          //and returns it as a String.
        System.out.println("The name typed in was: " + name);
    }
}

Let me know if you have any other questions.