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());

Java Program to add two numbers using BufferedReader

Example: How to add two numbers using BufferedReader in java.

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.print("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