Re: Beginner Problem - system.out.print
KyoGaSuki wrote:
Oh, sorry ^^;
Well, that was only my second java class (so this is going to be SO
embarassing..):
/**
* @(#)Digits.java
*
* Digits application
*
* @author
* @version 1.00 2008/1/17
*/
public class Digits {
public static void main(String[] args) {
// TODO, add your application code
int userNumber;
System.out.print("Enter a 4-digit integer: ");
}
}
I have absolutely no clue where to go after this...I know I am missing
something major in what I already have, though...I should be shot for
how little I understand this x.x
The next step is to find a method or class that knows how to bring things in
from the outside, the way System.out knows how to put things out to the outside.
So next take a look at the Javadocs for System.out and see if they lead you to
related things.
In the "Field Summary" section of the System Javadocs
<http://java.sun.com/javase/6/docs/api/java/lang/System.html>
we see that 'out' is a 'java.io.PrintStream' object, and that there is,
indeed, a related field, 'in', which is a 'java.io.InputStream'.
<http://java.sun.com/javase/6/docs/api/java/io/InputStream.html>
So one possible way to bring in information is via one of the InputStream
methods, like read().
The problem is, this version of read() seems rather crude. You're going to
face a lot of work converting raw bytes into useful information. So what else
is there around the java.io package more generally?
<http://java.sun.com/javase/6/docs/api/java/io/package-frame.html>
Oy. There's a lot there. At this point you might find yourself turning to
the tutorials in desperation.
<http://java.sun.com/docs/books/tutorial/essential/io/index.html>
It looks like
<http://java.sun.com/docs/books/tutorial/essential/io/scanfor.html>
might hold some relief.
This tutorial chapter discusses the java.util.Scanner class
<http://java.sun.com/javase/6/docs/api/java/util/Scanner.html>
which is chock-full of helpful methods.
Essentially, you wrap a Scanner instance around an input like System.in and
play with it from there.
There are also various java.io.Reader classes that you might find useful.
Enjoy.
--
Lew