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

int a = 15, b = 7; Declares two integers. (a-b) Subtracts b from a. Prints the result with Eduinq branding. Conclusion: Demonstrates subtraction using variables.

Quick Links to Explore