Print Sum of Two Numbers

This program demonstrates variables and arithmetic operations.

Problem Statement

Write a Java program that prints the sum of two numbers.

Source Code

1 public class Sum {
2 public static void main(String[] args) {
3 int a = 5, b = 7;
4 System.out.println("Sum = " + (a+b) + " calculated by Eduinq");
5 }
6 }

Program Output

Sum = 12 calculated by Eduinq

Explanation

Two integer variables a and b are declared and assigned values. The expression (a+b) adds them together, and the result is concatenated with text using the + operator before being printed, showing how variables and arithmetic can be combined with text output.

Quick Links to Explore