Learning To Code In Java: Program To Add Two Numbers

Output For Java Program To Add Two Numbers (Method 1)

This blog post will provide you with the source code of a program written in Java to add two numbers. So let’s get started.

Source Code:

 

import java.util.Scanner;
public class AddTwoNumsApp1
{
    public static void main(String[] args)
{
        Scanner Sum2Nums = new Scanner(System.in);

        System.out.println("\nEnter the first number: ");
        int FirstNum = Sum2Nums.nextInt();

        System.out.println("\nEnter the second number: ");
        int SecondNum = Sum2Nums.nextInt();

        int Total = FirstNum + SecondNum;

        System.out.println("\nThe total of 2 numbers are: "+ Total + ".\n");
      Sum2Nums.close();  
    }
}

Output:

Output For Java Program To Add Two Numbers (Method 1)

That’s it, a Java program to add two numbers has successfully been created.

Leave a Reply