Print Difference of Two Numbers

This program prints the difference between two numbers.

Problem Statement

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

Source Code

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

Program Output

Difference = 8 calculated by Eduinq

Explanation

Two integers a and b are declared, and the expression (a-b) subtracts b from a. The result is concatenated with descriptive text and printed, demonstrating subtraction using variables.

Quick Links to Explore