Java program to add two numbers using bufferedreader

Let’s learn java program to add two numbers using bufferedreader.

Java program to add two numbers using bufferedreader

In the below program to add two numbers using bufferedreader first get input from user using BufferedReader input line.

In the next step convert string to integer using Integer.parseInt() method.

This method returns the integer value represented by the argument in decimal.

Finally addition operator (+) is performed on two numbers and the result is stored in ‘add’ variable.

Here’s the java program.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AddTwoBufferedReader 
{
   public static void main(String[] args) throws NumberFormatException, IOException 
   {
      int number1, number2, add;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Please enter two numbers to add: ");
      number1 = Integer.parseInt(br.readLine());
      number2 = Integer.parseInt(br.readLine());
      add = number1 + number2;
      System.out.println("Add two numbers using bufferedreader: " + add);
   }
}


Output:

Please enter two numbers to add:
63
26
Add two numbers using bufferedreader: 89


Also read – continue statement in java