Java Program to Add Two Numbers

« Previous Program Next Program »

Add Two Numbers

To add two numbers in Java Programming, you have to ask to the user to enter the two number and place the addition of the two number in any variable then print the variable's value which is the addition result of the two number.

Java Programming Code to Add Two Numbers

Following Java Program ask to the user to enter the two number to add and display the addition result on the screen:

/* Java Program Example - Add Two Numbers */
import java.util.Scanner;

public class JavaProgram
    public static void main(String args[])
        int a, b, sum;
        Scanner scan = new Scanner(;
        System.out.print("Enter Two Numbers : ");
        a = scan.nextInt();
        b = scan.nextInt();
        sum = a + b;
        System.out.print("Sum of the Entered Two Number is " +sum);

When the above Java Program is compile and executed, it will produce the following output:

Java Program add two numbers

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.