Java Program to add two numbers using BufferedReader


In this program, You will learn how to add two numbers using InputStreamReader and BufferedReader in Java.


InputStreamReader is = new InputStreamReader(System.in);

BufferedReader br = new BufferedReader(is);

int a = Integer.parseInt(br.readLine());


Example: How to add two numbers using BufferedReader in Java

Run it Now
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main {
    public static void main(String args[]) throws IOException {

        int a, b, s;

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);

        System.out.println("Enter Two Numbers :");
        a = Integer.parseInt(br.readLine());
        b = Integer.parseInt(br.readLine());

        s = a + b;

        System.out.println("Sum is :" + s);

    }
}

Output:

Enter Two Numbers:
10
20
Sum is :30