Overview
This lesson explains how to perform basic arithmetic operations using Java programming. It
introduces addition, subtraction, multiplication, and division through simple, well-
commented code examples. This is ideal for beginners or as classroom reference material.
Java Program Code
java
CopyEdit
public class ArithmeticOperations {
public static void main(String[] args) {
int a = 20, b = 10;
// Addition
int sum = a + b;
System.out.println("Sum = " + sum);
// Subtraction
int diff = a - b;
System.out.println("Difference = " + diff);
// Multiplication
int product = a * b;
System.out.println("Product = " + product);
// Division
int quotient = a / b;
System.out.println("Quotient = " + quotient);
}
}
Sample Output
ini
CopyEdit
Sum = 30
Difference = 10
Product = 200
Quotient = 2
Educational Use
This Java lesson is valuable for classroom teaching or self-study. It reinforces the use of
variables and operators in Java while also building logical thinking.
Ideas for Extension:
Accept input from the user using Scanner
Handle decimal numbers using float or double
Include error-handling for division by zero