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 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,372 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!