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

Why does this not work out?

Beginning Java

import java.io.Console;

public class ab { public static void main(String[] args) { Console console = System.console(); String name = console.readLine("What is your name? ");

console.printf("My name is %s\n",name);
}

}

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hello Thieny Phan

Thanks for your query.

Please let us know if you are running this code on the IDE (Eclipse or Intellij) or is it on Workspace.

Thanks,

It's on eclipse IDE :(

1 Answer

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Thieny Phan

Thanks for coming back.

If you are on the Eclipse IDE you don't need the Console Object you need to import and use Scanner Object (from java.util package) instead.

//import util package
import java.util.*;
public class ab {
public static void main(String[] args) { 

Scanner scanner = new Scanner(System.in);  
System.out.print("Enter your name: \n"); 

//when prompted at the bottom terminal enter your name and hit enter button to proceed
String name = scanner.nextLine();  

System.out.printf("My name is %s\n",name);
}

Cheers Sir