Addition of Two Numbers in Java by User Input

Addition of Two Numbers by User Input

Here, you will learn to program Addition of two numbers in Java by user input. This program enables the user to adding two numbers in java by using 3 different methods.

1. using command line arguments.

2. using Scanner Class

3. using Buffered readers

Addition of two Numbers in Java using Command Line Arguments

This program enables the user to adding two numbers in java using command line arguments.

Output

Addition of Two Numbers in Java

 

Addition of two Numbers in Java using Scanner

Let’s do the Sum of Two Numbers program by using scanner class, to get input from the user.

Output

C:\CodeRevise\java>javac AdditionWithScanner.java

C:\CodeRevise\java>java AdditionWithScanner

Enter the value of a and b
7 9
Addition of 7 and 9 is = 16

 

Addition of two Numbers in Java using Buffered readers

Let’s do the Sum of Two Numbers program by using Buffered Reader, to get input from the user.

Output

C:\CodeRevise\java>javac additionByBR.java

C:\CodeRevise\java>java additionByBR
Enter two numbers : 12
34
SUM = 46

 

 

Check out our other Java Programming Examples

 

 

 

Leave a Comment

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

Scroll to Top