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

Hi, How to read text from the user in Java instead of writing console.printf method

Other ways to read input from user

1 Answer

Hi!

There are two major ways to get user input in java:

First way:

import java.io.Console;
import java.util.scanner;
Scanner sc = new Scanner(System.in);
console.printf("Name: ");
String name = sc.nextString();

Second way:

import java.io.Console;
console.printf("Name: ");
String name = console.readLine();

I hope that helps!

Thanks! :)

Thanks A lot Aayush Mitra. I appreciate it