Results 1 to 5 of 5
  1. #1
    Axle12693 is offline Member
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Default VERY new to this

    Hey guys... I just started learning Java about an hour ago.

    What's wrong with this line of code?
    Project = System.console().readLine();

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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

  3. #3
    JDScoot is offline Member
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    24
    Rep Power
    0

    Default

    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: ");

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    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:
    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
    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.

  5. #5
    JDScoot is offline Member
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    24
    Rep Power
    0

    Default

    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.
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •