Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Java coding for user input?
I have to prompt the user to enter in their student id #, their first name, and their last name. Does that go through the Scanner import? What is java.io.*?
So I need to take in that information and then display it. How am I to do this?
*No need to put out the entire code. Maybe just give me some hints or tell me about some functions that I can use. That would be greatly appreciated, thanks!
2 Answers
- husoskiLv 77 years agoFavorite Answer
You only see java.io.* on an import statement. That just says, "Import all of the classes defined in the java.io package."
The java.io package has all of the basic I/O classes. If you want to peek at what http://docs.oracle.com/javase/7/docs/api/index.htm...
That's quite a lot. If you plan to use Java for serious work, get used to looking things up there. You can navigate using the left frames to select a specific package, or "All Classes" on the top left, then find the class you want on the bottom left. And so on.
A quicker index, if you know the class name, is a web search for "java 7 scanner", substituting any standard class name for for "scanner" (and you don't want quotes in your search.) What you want is almost always the first hit.
The Scanner class is not part of the java.io package though. That's probably because it also operates on String input. Scanner is in the java.util package.
For console I/O, you can use Scanner on the System.in object for all of your input, and any PrintStream methods on the System.out object for all console output.
A simple example (assuming java.util.Scanner or java.util.* has been imported):
Scanner sysin = new Scanner(System.in);
System.out.print("Tell me your name: ");
String name = sysin.nextLine(); // input whole line for name
System.out.print("How old are you? ");
int age = sysin.nextInt();
System.out.println("Hi " + name + ".");
System.out.println("You are " + age + " years old today.");
Wrap that in a class and a main() method and give it a try.
- 7 years ago
Only answer, and yet I don't think anyone else could have said it any better. Thank you!