Read an Integer in from the Keyboard (Rated 0)Description:
This little code snippet is very useful to demonstrate how you could read a string in as an integer so that you can perform mathmatical analysis on it. Code starts here
class X {
public static void main(String argv[]) throws IOException {
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter your name");
String name = in.readLine();
System.out.println("Enter your age");
int age = Integer.parseInt(in.readLine());
System.out.println(name + " you are " + age + " years old.");
}
}
Submitted by Devscripts on 24-02-2003 12:10 |