3.1 Lesson Outcomes
After completing this lesson, learners will be able to:
- Perform mathematical calculations in Java.
- Use Java Math class methods.
- Generate random numbers.
- Apply rounding operations.
- Use numeric functions in Java applications.
3.2 Overview
Java provides built-in mathematical functionality through operators and the Math class. Developers use Java number functions for:
- calculations,
- financial systems,
- scientific applications,
- gaming,
- and data processing.
This lesson introduces learners to practical numeric operations and mathematical functions in Java programming.
Understanding Java number functions is important because calculations are widely used in software development.
PA1601 — Perform Basic Mathematical Operations
Java supports arithmetic calculations using operators.
Arithmetic Operator — Purpose
- — Addition
- — Subtraction
- — Multiplication
/ — Division
% — Modulus
Java Example:
int a = 10;
int b = 5;
System.out.println(a + b);
System.out.println(a – b);
System.out.println(a * b);
System.out.println(a / b);
Practical Activity
Learners must:
- perform calculations,
- apply arithmetic operators,
- and display results.
PA1602 — Use Math.max() and Math.min()
Java Math class provides methods for maximum and minimum values.
Java Example:
System.out.println(Math.max(10, 20));
System.out.println(Math.min(10, 20));
Practical Activity
Learners must:
- find maximum values,
- find minimum values,
- and display outputs.
PA1603 — Use Math.sqrt() and Math.pow()
Java supports square root and power calculations.
Java Example:
System.out.println(Math.sqrt(64));
System.out.println(Math.pow(2, 3));
Practical Activity
Learners must:
- calculate square roots,
- calculate powers,
- and display results.
PA1604 — Use Math.abs()
Math.abs() returns absolute values.
Java Example:
System.out.println(Math.abs(-15));
Practical Activity
Learners must:
- calculate absolute values,
- test negative numbers,
- and display outputs.
PA1605 — Apply Rounding Functions
Java supports multiple rounding methods.
Math Method — Purpose
Math.round() — Rounds to nearest number
Math.ceil() — Rounds upward
Math.floor() — Rounds downward
Java Example:
System.out.println(Math.round(4.6));
System.out.println(Math.ceil(4.2));
System.out.println(Math.floor(4.9));
Practical Activity
Learners must:
- apply rounding methods,
- compare outputs,
- and display results.
PA1606 — Generate Random Numbers
Java can generate random numeric values.
Java Example:
System.out.println(Math.random());
Practical Activity
Learners must:
- generate random numbers,
- display values,
- and test outputs.
PA1607 — Generate Random Numbers Within a Range
Random values can be generated within specific ranges.
Java Example:
int randomNum =
(int)(Math.random() * 100);
System.out.println(randomNum);
Practical Activity
Learners must:
- generate random integers,
- control numeric ranges,
- and display outputs.
PA1608 — Create Complete Number Program
Java number functions are used in practical applications.
Java Example:
public class NumberExample {
public static void main(String[] args) {
int a = 20;
int b = 10;
System.out.println(a + b);
System.out.println(Math.max(a, b));
System.out.println(Math.sqrt(64));
System.out.println(Math.random());
}
}
Importance of Numbers in Java
Java number functionality supports:
- calculations,
- simulations,
- automation,
- and enterprise software development.
3.5 Key Notes / Summary
- Java supports arithmetic calculations.
- Math class provides advanced functions.
- Math.max() finds maximum values.
- Math.sqrt() calculates square roots.
- Java supports rounding functions.
- Math.random() generates random values.
- Numeric operations are widely used in software applications.