If you don't want to get too deep into the lessons yet then try this
little chunk.
//listing 1
// Read a character from the keyboard.
class KbIn {
public static void main(String args[])
throws java.io.IOException {
char ch;
System.out.print("Press a key followed by ENTER: ");
ch = (char) System.in.read(); // get a char
System.out.println("Your key is: " + ch);
}
}
One (char)acter at a time is why read() will cast to a char. It is not
designed for more than that.
So we need a reader method. That's what the BufferedReader class does.
See:
http://www.javadoconline.com/search.jsp?from=main&class=BufferedReader&action=search
Notice we still use throws java.io.IOException in the main class.
One could use an array and construct the name string but we would have
to type enter for every letter. There are a lot of java classes ready
made for us in the JDK. All we then need to do is learn how to use
them.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---