Results 1 to 5 of 5
Thread: VERY new to this
- 06-12-2011, 11:45 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 1
- Rep Power
- 0
- 06-12-2011, 11:52 PM #2
Does it give an error? Please copy and paste here the full text of the error message.
Have you looked at the API doc for the System class? Does it have a method console()?
If you just started learning java, I suggest that you become familiar with the Java SE API documentation:
Java Platform SE 6
To find the API doc for a specific class, use the lower left panel, scroll down to the class you are interested in.
And the Java tutorial: The Java™ Tutorials
- 06-12-2011, 11:55 PM #3
Member
- Join Date
- Jun 2011
- Location
- San Diego, CA
- Posts
- 24
- Rep Power
- 0
Take a look at this link. It has the code you are looking for Java Console readLine : Console*«*JDK 6*«*Java
Basically you should do as follows:
Java Code:Console console = System.console(); String Username = console.readLine("Enter you user name: ");
- 06-13-2011, 12:09 AM #4
If you take what the OP posted, there isn't anything wrong with it. Add: String Project; to the code and it compiles and executes.
This is my test code:
System.console() is a static method that returns a Console object. The Console object has a readLine() method that will read a line from the console.Java Code:String Project; // Define a String variable to use on the line of code in question Project = System.console().readLine(); System.out.println("P=" + Project); // show the result
- 06-13-2011, 12:29 AM #5
Member
- Join Date
- Jun 2011
- Location
- San Diego, CA
- Posts
- 24
- Rep Power
- 0
Makes sense. That is probably more what the OP was looking for. I just did a quick google search and the example I posted was the first thing to pop up in the google search.If you take what the OP posted, there isn't anything wrong with it. Add: String Project; to the code and it compiles and executes.


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks