Java Program to Add Two Numbers Taking Input From User

Java Program to add two numbers taking input from user. In this program, you will learn how to write an addition of two numbers in a java program. This software can combine two separate numbers into a single number. Here’s a java program for beginners in the java program that does addition with the third variable.

Operator and Operands in Java

The constructions that may alter the values of the operands are known as operators. Consider the formula 2 + 3 = 5, where the operands are 2 and 3 and the operator is +. In Java, an operator is a specific symbol or keyword that denotes a mathematical operation or another sort of operation that may be performed on one or more operands.

How to Sum of Two Numbers in Java User Input

In Java, the + operator is used to multiply two integers. Using the Scanner class, get the needed values from the user and use the + operator to combine them. Sum() is a Java built-in method that returns the total of its inputs. 

The technique uses the + operator to add two numbers together. The syntax is as follows: sum public static int (int a, int b) Parameter: Two parameters are accepted by the procedure, which must be combined together: a: the initial digit of the integer value. 

nextInt() Function in Java

nextInt() is a method that returns an integer. As an int scans the next token of the input. The invocation of this method with the form nextInt() works in the same way as the invocation with the form nextInt(). nextInt(radix), where radix is the scanner’s default radix. A Scanner object’s nextInt() function takes a string of digits and transforms it to an int type.

import java.util.Scanner;
public class Main
public static void main(String[] args)
int a, b, sum;
Scanner sc = new Scanner(;
System.out.println("Enter First Number: ");
a = sc.nextInt();
System.out.println("Enter Second Number: ");
b = sc.nextInt();
sum = a + b;
System.out.println("Sum of these numbers: "+sum);


The sum is 300

Operators in Java

Addition, subtraction, multiplication, division, exponentiation, and modulus operations are all performed using the arithmetic operators. Mathematical calculations are carried out using arithmetic operators. The assignment operators are used to give a property or variable a value. Numeric, date, system, time, and text can all be used as assignment operators. To perform comparisons, comparison operators are needed. 

Arithmetic Operator and Logical Operator

The acts of arithmetic operators are performed on numbers. Logical operators compare two values and return a “true” or “false” depending on whether the comparison is true (or false). These are main functions are done using operator in java addition program