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 trialThieny Phan
48 PointsWhy 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);
}
}
Thieny Phan
48 PointsIt's on eclipse IDE :(
1 Answer
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsThanks 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
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsTonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsHello 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,