I need help with java
Author |
Message |
mar5000k
|
Posted: Thu Sep 13, 2012 10:59 am Post subject: I need help with java |
|
|
I am teaching my self Java programming and still doing introduction and orientation.
My problem is, How do I prompt for user input?? The book I am reading says that TextIO.getlnint() is not a built in function. That, it should be writen or created for each program I write, however I have no idea where to start from. Any help please? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
DemonWasp
|
Posted: Thu Sep 13, 2012 12:00 pm Post subject: RE:I need help with java |
|
|
Input is usually by InputStreams (there are several different kinds). The console input stream is known as System.in .
To make your life easier, you usually want to use the Scanner class (available since Java 1.5): Scanner in = new Scanner ( System.in ); . Now, the Scanner instance in will read from standard input.
For example, you might want to ask someone their name:
code: |
Scanner in = new Scanner ( System.in );
System.out.println ( "Please enter your name" );
String name = in.nextLine();
|
|
|
|
|
|
 |
mar5000k
|
Posted: Thu Sep 13, 2012 3:10 pm Post subject: RE:I need help with java |
|
|
Thank you DemonWasp! You gave me some light. |
|
|
|
|
 |
wtd
|
Posted: Thu Sep 13, 2012 10:55 pm Post subject: RE:I need help with java |
|
|
Not to toot my own horn, but: Introduction to Java. |
|
|
|
|
 |
|
|