Write a Java Program to Print the Sum of Two Numbers

December 20, 2022 0 Comments

In this tutorial learn how you can print the sum of two numbers in java. We will define two variables and use another variable sum for storing the result. Then we print the result.

Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.

Write a Program to Print the Sum of Two Numbers

Here is the code to display the sum of two numbers in Java programming.

//Write a Java program to print the sum of two numbers
import java.util.Scanner;

public class Suminput {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter First Number:");
        int a = sc.nextInt();
        System.out.println("Enter Second Number:");
        int b = sc.nextInt();
        int sum = a + b;
        System.out.println("The sum of two number a and b is " + sum + ".");
    }

}

Test Live At Jdoodle

Conclusion

This is how you can display the sum of two numbers in java programming. Comment below if you like our tutorial.

Leave a comment

Gallery