Try this:
import java.io.*;
public class ReadKeyB {
public static void main (String args[]) {
DataInputStream in = new DataInputStream(System.in);
String s ;
try {
s = in.readLine();
int myint = new Integer(s).intValue();
myint++;
System.out.println(myint);
}
catch (Exception e) {
System.out.println("Error: " + e.toString());
}
}
}
readLine() is deprecated in jdk1.2 but it does the job. The main idea is
you get the string, parse it into an Integer object and extract the int
value, add one & print. From here you could use a non deprecated function.
hope this helps.
Carlitos.
Friendship wrote:
> Hi, guru,
>
> I am very new to java.
> I want read a int from keyboard and plus one, then
> display it.
> But why it doesn't work?
> Help me please!!
>
> Thanks & Have nice weekend!!
>
> import java.io.*;
> public class ReadKeyB {
>
> public static void main (String args[]) {
>
>
> DataInputStream in = new DataInputStream(System.in);
> int s ;
>
> try {
> s = in.readInt();
> int myint = intValueOf(s);
> myint++;
> System.out.println(myint);
> }
>
>
> catch (Exception e) {
> System.out.println("Error: " + e.toString());
> }
>
>
> }
>
> }
>
> __________________________________________________
> Do You Yahoo!?
> Get Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]