To add two numbers given by user using DataInputStream method

DataInputStream :

by using DataInputStream method we can take input from user.
 

Program : 

import java.io.DataInputStream;
class AddDataInputStream
{
public static void main(String [] args)
{

DataInputStream s = new DataInputStream(System.in);
int a=0,b=0;
try

{
System.out.print("enter the value of integer  number a=");

a=Integer.parseInt(s.readLine());
System.out.print("enter the value of integer  number b=");
b=Integer.parseInt(s.readLine());


}
catch (Exception e) { }
int c;
c=a+b;
System.out.println("sum of a and b variable is="+c);
}
}

No comments:

Post a Comment