Create a program that will accept two numbers from a user and display their sum. As we know that the readLine() function reads the entered text as string,whereas calculations can be made only on numeric values(having data type int,float,double)only. Hence, convert the entered string values into numeric values before making the calculation.

import java.io.*;
public class UsingStream
{
    public static void main(String ags[])throws IOException
	{
	   int num1;
	   int num2;
	   int num;
	   InputStreamReader objectISR=new InputStreamReader(System.in);
	   BufferedReader objectBR=new BufferedReader(objectISR);
	   System.out.printIn("Enter First Number");
	   String n1=objectBR.readLine();
	   num1=Integer.parseInt(n1)
	   System.out.printIn("Enter Second Number");
	   String n2=objectBR.readLine();
	   num2=Integer.parseInt(n2);
	   System.out.printIn('\f');
	   sum=num1+num2;
	   System.out.printIn("Sum of"+num1+"and"+num2+"is :"+sum);
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Show Buttons
Hide Buttons