Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Getting Started with Java Receiving Input

I'm not using console,I used System.out &its been working so far but now for System.out.printf.readLine(" ") ...

it doesnt work, It says 'Error: printf cannot be resolved or is not a field' , What can I do to make this work without putting console

1 Answer

Armin Halilovic
Armin Halilovic
3,359 Points

Hi Carolina, maybe you have already found an answer in the meantime but nonetheless here is one possible way to get the input from the user without using the console keyword:

There is a Scanner class in Java which allows to scan text. You have to import the Scanner class, create a Scanner object and use the .nextLine() method to read the input from the user:

import java.io.Console;

import java.util.Scanner;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();

    // Create the Scanner Object
    Scanner scanner = new Scanner(System.in);

    // Print out your statement to the user
    System.out.printf("Enter Username: \n");

    // Read the user input (strings)
    String userName = scanner.nextLine();
    // Print out the input from the user

    // To read integers you have to use nextInt()
    // To read doubles you have to use nextDouble()
    // and so on...

} }

Hope this helps!