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

int a = 5, b = 7; Declares two integer variables and assigns values. (a+b) Adds the two numbers. "Sum = " + (a+b) Concatenates text with the result. System.out.println(...) Prints the final message with Eduinq branding. Conclusion: This program shows how variables store values and how arithmetic operations can be combined with text output.

Quick Links to Explore