Open notepad or any text editor and type this code.
and save this file as userio.java in the bin directory (c:\j2sdk1.4.2\bin).
import java.io.*;
class userio
{
public static void main(String args[]) throws IOException
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
String a,b;
System.out.print("Enter 1st no: ");
a=ob.readLine();
System.out.print("Enter 2nd no: ");
b=ob.readLine();
int c=Integer.parseInt(a)+Integer.parseInt(b);
System.out.println("The Sum is: "+c);
}
} and save this file as userio.java in the bin directory (c:\j2sdk1.4.2\bin).
Now open command prompt and go to your Java directory.
Now compile your program by typing javac userio.java
Now the program will be compiled.
Now Run your program by typing java userio
No comments:
Post a Comment