Mathematical Library Methods ICSE Class 10 Computer Applications
Updated 14 October 2026 · Fact-checked
The Math class in the default package java.lang provides ready-made methods: pow(x, y), sqrt(x), cbrt(x), ceil(x), floor(x), round(x), abs(a), max(a, b), min(a, b) and random(). Most return double; round returns a whole number (long for a double), and abs, max and min return the type of their arguments. ICSE Class 10 tests their outputs and their use in Java expressions.
What Mathematical Library Methods is about
Both recent board papers tested Math method outputs: Math.ceil(5.4) + Math.ceil(4.5) and 'which method returns only an integer?' (2024), Math.max(-7, Math.min(-5, -4)) (2025), and Java expressions with Math.abs and Math.sqrt (2024, 2025). The commonest losses come from forgetting that ceil and floor return doubles (11.0, not 11), from rounding negative numbers, and from missing * between terms.
The syllabus asks for an introduction to java.lang (the default package), the methods pow(x, y), sqrt(x), cbrt(x), ceil(x), floor(x), round(x), abs(a), max(a, b), min(a, b) and random(), and writing Java expressions using operators and Math methods.
Weightage: CISCE publishes no chapter weightage. Section A (40 marks) is compulsory: 1-mark MCQs and 2-mark short answers including output and error questions; in Section B you answer any four of six 15-mark programming questions written in Java.Source: CISCE ICSE Computer Applications (661) specimen paper structure for 2027
Key concepts
- The Math class and java.lang
Math is a class in the java.lang package, which every program imports automatically, so no import statement is needed. Its methods are static, so they are called with the class name and the dot operator: Math.sqrt(25). The class also provides the constant Math.PI (3.141592653589793).
Worked example
(1 mark) Why does a program using Math.sqrt() not need an import statement?
Try it first, then show the solutionSolution
- Math is in java.lang, which is imported by default.
Answer: Because the Math class belongs to java.lang, the default package that is automatically available to every Java program.
- pow, sqrt and cbrt
Math.pow(x, y) returns x raised to the power y, as a double: Math.pow(2, 3) = 8.0; Math.pow(9, 0.5) = 3.0; Math.pow(2, -1) = 0.5.
Math.sqrt(x) returns the positive square root as a double: Math.sqrt(49) = 7.0; Math.sqrt(2.25) = 1.5. The square root of a negative number gives NaN (not a number).
Math.cbrt(x) returns the cube root as a double: Math.cbrt(27) = 3.0; Math.cbrt(-8) = -2.0 (cube roots of negatives are allowed).Worked example
(2 marks) Give the output: System.out.println(Math.pow(4, 2) + Math.sqrt(16) + Math.cbrt(-27));
Try it first, then show the solutionSolution
- 16.0 + 4.0 = 20.0 - 1 mark.
- 20.0 + (-3.0) = 17.0 - 1 mark.
Answer: 17.0
- ceil, floor and round
Math.ceil(x) returns the smallest whole number greater than or equal to x, as a double: Math.ceil(5.4) = 6.0; Math.ceil(-5.4) = -5.0; Math.ceil(7.0) = 7.0.
Math.floor(x) returns the largest whole number less than or equal to x, as a double: Math.floor(5.9) = 5.0; Math.floor(-5.4) = -6.0.
Math.round(x) returns the nearest whole number; a .5 goes up (towards positive infinity). It returns long for a double argument (int for a float): Math.round(4.5) = 5; Math.round(4.49) = 4; Math.round(-4.5) = -4; Math.round(-4.6) = -5. (It works as floor(x + 0.5).)Of ceil, floor, sqrt and round, only round returns an integer type.
Worked example
(1 mark) What is the output of Math.ceil(5.4) + Math.ceil(4.5)?
(a) 10.0
(b) 11.0
(c) 12.0
(d) 9.0Try it first, then show the solutionSolution
- ceil(5.4) = 6.0 and ceil(4.5) = 5.0; sum 11.0 (a double).
Answer: (b) 11.0
- abs, max and min
Math.abs(a) returns the absolute (non-negative) value, of the same type as a: Math.abs(-7) = 7; Math.abs(-7.5) = 7.5.
Math.max(a, b) returns the larger, Math.min(a, b) the smaller, of the same type as the arguments; if one is double, the result is double: Math.max(3, 8) = 8; Math.min(4, 4.5) = 4.0.
Nested calls are evaluated from the inside out: Math.max(-7, Math.min(-5, -4)) → Math.min(-5, -4) = -5 → Math.max(-7, -5) = -5.
Largest of three: Math.max(a, Math.max(b, c)).Worked example
(1 mark) The output of Math.max(-7, Math.min(-5, -4)) is:
(a) -5
(b) -4
(c) -7
(d) errorTry it first, then show the solutionSolution
- Inner: min(-5, -4) = -5. Outer: max(-7, -5) = -5.
Answer: (a) -5
- random() and Java expressions
Math.random() returns a random double from 0.0 (inclusive) up to, but not including, 1.0. To get a random whole number from 1 to n: (int)(Math.random() * n) + 1. A dice throw: int dice = (int)(Math.random() * 6) + 1; gives 1 to 6. A number from a to b: (int)(Math.random() * (b - a + 1)) + a.
Writing Java expressions with Math methods:
√(a² + b²) → Math.sqrt(a * a + b * b)
|x − y| → Math.abs(x - y)
x³ + ∛y → Math.pow(x, 3) + Math.cbrt(y)
A = P(1 + r/100)ⁿ → p * Math.pow(1 + r / 100, n) (r should be double)
√P × √Q → Math.sqrt(p) * Math.sqrt(q)Worked example
(2 marks) Write the Java expression for the product of the square root of P and the square root of Q.
Try it first, then show the solutionSolution
- Square roots with Math.sqrt - 1 mark.
- Multiplication sign * between them - 1 mark.
Answer: Math.sqrt(p) * Math.sqrt(q)
Mathematical Library Methods in real life
Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Math.ceil for packing
Suppose 53 students are going on a trip and each van seats 10. A program must work out how many vans to book.
Which Math method gives the correct number of vans, and what is the answer?
Try it first, then show the solutionSolution
- 53 / 10.0 = 5.3 vans.
- Part of a van still needs a whole van: round up.
- Math.ceil(5.3) = 6.0, so 6 vans.
Answer: Math.ceil(53 / 10.0) = 6.0, so 6 vans (floor or round would leave 3 students behind).
Memory hook: Ceiling is up; floor is down.
Math.random
Imagine a board-game app that must roll a fair six-sided die.
Write the Java statement and explain why it gives 1 to 6.
Try it first, then show the solutionSolution
- Math.random() gives 0.0 to just under 1.0.
- Multiply by 6: 0.0 to just under 6.0; (int) gives 0 to 5.
- Add 1: 1 to 6.
Answer: int dice = (int)(Math.random() * 6) + 1; it produces whole numbers from 1 to 6 with equal chance.
Memory hook: Random × n, cut, plus one.
Math.abs for differences
Suppose a weather app shows the gap between today's temperature (−3 °C) and yesterday's (4 °C) as a positive number.
Which method helps and what is the result?
Try it first, then show the solutionSolution
- The difference −3 − 4 = −7 is negative.
- A gap should be positive: Math.abs(-7) = 7.
Answer: Math.abs(today - yesterday) = 7, the size of the change regardless of direction.
Memory hook: abs drops the minus.
Topics in this chapter
Mathematical Library Methods: syntax and key facts
- Return types
- 1.pow, sqrt, cbrt, ceil, floor, random
- 2.double; round(double)
- 3.long; abs, max, min
- 4.type of arguments
- So ceil(4.2) prints 5.0.
- Rounding rules
- ceil up; floor down; round = floor(x + 0.5)
- round(-2.5) = -2; floor(-2.5) = -3.0; ceil(-2.5) = -2.0.
- Random integer
- (int)(Math.random() * (b - a + 1)) + a
- From a to b inclusive.
How the board asks Mathematical Library Methods
The question patterns to expect, and the method that works for each.
| Question type | How it is asked | Method |
|---|---|---|
| Output MCQ (Section A) | Math.ceil(5.4) + Math.ceil(4.5) (2024); Math.max(-7, Math.min(-5, -4)) (2025); which method returns only an integer (2024). | Evaluate inner calls first; remember double results print with .0. |
| Java expression (2 marks) | |a + b| / √(a² + b²) (2024); √P × √Q (2025). | Replace each mathematical symbol with the matching Math method and add * for products. |
| Program (15 marks) | Formula-based programs: compound interest, distance, areas, roots. | Use double variables and Math methods; print with clear labels. |
Tricks to remember Mathematical Library Methods
Short memory aids. Say each one aloud once, then use it on a question the same day.
Ceiling above, floor below
On a number line, ceil goes right (up), floor goes left (down), even for negatives.
Use it when: ceil(-5.4) = -5.0; floor(-5.4) = -6.0.
Only round is whole
Of ceil, floor and round, only round gives an integer type.
Use it when: Return-type MCQs.
Mathematical Library Methods: board-level solved questions
Ordered from board level to HOTS. Cover the solution, write your own, then compare step by step.
Example 1: Which returns an integer? · 1 mark · MCQBoard level
Which method returns an integer type?
(a) Math.ceil(n)
(b) Math.sqrt(n)
(c) Math.floor(n)
(d) Math.round(n)
Try it first, then show the solutionSolution
- ceil, floor and sqrt return double; round returns long/int.
Answer: (d) Math.round(n)
Example 2: Negative rounding · 1 mark · MCQHOTS / competency
What is printed by System.out.println(Math.round(-6.5) + " " + Math.floor(-6.5) + " " + Math.ceil(-6.5));
(a) -7 -7.0 -6.0
(b) -6 -7.0 -6.0
(c) -6 -6.0 -7.0
(d) -7 -6.0 -6.0
Try it first, then show the solutionSolution
- round(-6.5) = floor(-6.0) = -6; floor(-6.5) = -7.0; ceil(-6.5) = -6.0.
Answer: (b) -6 -7.0 -6.0
Example 3: Assertion and reason: return types · 1 mark · Assertion-reasonHarder board level
Assertion (A): System.out.println(Math.sqrt(36)); prints 6.0.
Reason (R): Math.sqrt() always returns a double value.
(a) Both A and R are true and R is the correct explanation of A
(b) Both A and R are true but R is not the correct explanation of A
(c) A is true but R is false
(d) A is false but R is true
Try it first, then show the solutionSolution
- sqrt returns double, so 6.0 is printed.
Answer: (a) Both A and R are true and R is the correct explanation of A
Example 4: Expression from formula · 2 marks · Very short answerBoard level
Write the Java expression for |a + b| / √(a² + b²).
Try it first, then show the solutionSolution
- |a + b| → Math.abs(a + b).
- √(a² + b²) → Math.sqrt(a * a + b * b).
Answer: Math.abs(a + b) / Math.sqrt(a * a + b * b)
Example 5: Mixed output · 2 marks · Short answerHarder board level
Give the output:
double a = 2.7, b = -2.7;
System.out.println(Math.floor(a) + Math.ceil(b));
System.out.println(Math.round(a) + Math.round(b));
System.out.println(Math.max(Math.abs(b), a));
Try it first, then show the solutionSolution
- floor(2.7) = 2.0; ceil(-2.7) = -2.0; sum 0.0.
- round(2.7) = 3; round(-2.7) = -3; sum 0 (long).
- abs(-2.7) = 2.7; max(2.7, 2.7) = 2.7.
Answer: 0.0
0
2.7
Example 6: Compound interest program · 15 marks · Long answerHarder board level
Write a program to accept principal P, rate R (% per annum) and time N (years), and print the amount A = P(1 + R/100)ᴺ rounded to the nearest rupee, and the compound interest.
Try it first, then show the solutionSolution
- import java.util.Scanner;
class Compound
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Principal: ");
double p = sc.nextDouble();
System.out.print("Rate: ");
double r = sc.nextDouble();
System.out.print("Years: ");
int n = sc.nextInt(); - double a = p * Math.pow(1 + r / 100, n);
long amount = Math.round(a);
long ci = amount - Math.round(p); - System.out.println("Amount = " + amount);
System.out.println("Compound interest = " + ci);
}
} - r is double so r / 100 is not integer division.
- Trace: 10000, 10, 2: 1 + 0.1 = 1.1; 1.1² ≈ 1.21; a ≈ 12100.000000000002; Math.round gives 12100; ci = 12100 − 10000 = 2100.
Answer: Sample run:
Principal: 10000
Rate: 10
Years: 2
Amount = 12100
Compound interest = 2100
Example 7: Distance and hypotenuse · 15 marks · Long answerHOTS / competency
Write a program to accept the coordinates (x1, y1) and (x2, y2) of two points and print the distance between them, √((x2 − x1)² + (y2 − y1)²), and the larger of |x2 − x1| and |y2 − y1|.
Try it first, then show the solutionSolution
- import java.util.Scanner;
class Distance
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("x1 y1 x2 y2: ");
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble(); - double dx = Math.abs(x2 - x1);
double dy = Math.abs(y2 - y1);
double d = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); - System.out.println("Distance = " + d);
System.out.println("Larger gap = " + Math.max(dx, dy));
}
} - Trace with 1 2 4 6: dx = 3.0, dy = 4.0; 9.0 + 16.0 = 25.0; sqrt = 5.0; max = 4.0.
Answer: Sample run:
x1 y1 x2 y2: 1 2 4 6
Distance = 5.0
Larger gap = 4.0
Case-study practice (Section B style)
Read the situation, then answer every part. In the board paper this is a 10-mark question split into 2 + 3 + 5 marks.
The tile shop
Imagine a tile shop's program: a room has area 23.4 square metres; each box covers 2 square metres. The owner wants the number of boxes, the cost at ₹845.50 per box rounded to the nearest rupee, and a lucky-draw number from 1 to 100 for each customer.
(i) · 2 marks
Write the expression for the number of boxes and give its value.
Answer
Answer: Math.ceil(23.4 / 2) = Math.ceil(11.7) = 12.0, so 12 boxes.
Expression 1 mark; value 1 mark.
(ii) · 3 marks
Write the expression for the rounded cost of 12 boxes and give its value.
Answer
Answer: Math.round(12 * 845.50) = Math.round(10146.0) = 10146.
Expression 2 marks; value 1 mark.
(iii) · 5 marks
Write the statement for the lucky-draw number and explain how it works. Why would floor be wrong for the boxes?
Answer
Answer: int lucky = (int)(Math.random() * 100) + 1; random() gives 0.0 to under 1.0; × 100 gives 0.0 to under 100.0; casting gives 0 to 99; adding 1 gives 1 to 100. Math.floor(11.7) = 11.0 would leave 1.4 square metres uncovered, so ceil is needed.
Statement 2 marks; explanation 2 marks; floor 1 mark.
Where the marks are
How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.
Write the Java expression for |a + b| / √(a² + b²). (2 marks) (2 marks)
| Step | Marks |
|---|---|
| Math.abs(a + b) numerator. | 1 |
| Math.sqrt(a * a + b * b) denominator with /. | 1 |
Program: compound interest with Math.pow and Math.round. (15 marks) (15 marks)
| Step | Marks |
|---|---|
| Class, main, Scanner and inputs with suitable types. | 3 |
| Correct formula with Math.pow and double rate. | 5 |
| Rounding with Math.round. | 2 |
| Interest = amount − principal. | 2 |
| Output with labels. | 3 |
Where students lose marks in Mathematical Library Methods
The slips examiners see most often, and what to write instead.
Mistake: Missing Math.abs for |x|
The 2024 examiners noted candidates ignored the | | symbol or did not recognise it as absolute value.
Do this: Every | | becomes Math.abs( ).
Usually costs: 1 mark.
Mistake: Missing * between Math calls
In 2025 candidates wrote Math.sqrt(p) Math.sqrt(q) without *.
Do this: Products always need *.
Usually costs: 1 mark.
Mistake: Writing 11 instead of 11.0
ceil and floor return double; options test this.
Do this: Show .0 for double results.
Usually costs: 1 mark.
Mistake: Using Math.pow instead of Math.sqrt for the NORM
In the 2025 NORM program the examiners saw the square root ignored or replaced by pow.
Do this: Square root of a sum: Math.sqrt(sum).
Usually costs: 1 to 2 marks of 15.
Practice questions on Mathematical Library Methods
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
Math.floor(-4.2) returns:
(a) -4.0
(b) -5.0
(c) -4
(d) 4.0Hint
Down the number line.
Answer
(b) -5.0
Q2 · 1 mark · MCQHOTS / competency
Math.round(7.5) + Math.round(-7.5) gives:
(a) 0
(b) 1
(c) -1
(d) 15Hint
floor(x + 0.5).
Answer
(b) 1 (8 + (-7))
Q3 · 1 mark · MCQBoard level
Math.cbrt(64) returns:
(a) 8.0
(b) 4.0
(c) 4
(d) 16.0Hint
Cube root, double.
Answer
(b) 4.0
Q4 · 2 marks · Very short answerBoard level
Write Java expressions: (i) x³ + ∛y (ii) A = πr²
Hint
pow, cbrt, PI.
Answer
(i) Math.pow(x, 3) + Math.cbrt(y) (ii) a = Math.PI * r * r; (or Math.PI * Math.pow(r, 2))
Q5 · 2 marks · Very short answerHarder board level
Give the output: System.out.println(Math.min(4, 4.5) + Math.abs(-3));
Hint
Mixed types become double.
Answer
7.0 (min gives 4.0 because one argument is double; 4.0 + 3 = 7.0)
Q6 · 2 marks · Very short answerHarder board level
Write a statement that stores a random integer from 10 to 20 (both included) in n.
Hint
b − a + 1 = 11.
Answer
int n = (int)(Math.random() * 11) + 10;
Q7 · 2 marks · Short answerHOTS / competency
Give the output: double x = 9; System.out.println(Math.sqrt(x) + Math.abs(-x / 3) + "" + Math.ceil(x / 2));
Hint
Left to right; then string join.
Answer
6.05.0 (3.0 + 3.0 = 6.0; then "6.0" + "" + "5.0" joins as text)
Q8 · 15 marks · Long answerHarder board level
Write a program to accept the radius of a sphere and print its volume (4/3 πr³) and surface area (4πr²), each rounded to the nearest whole number.
Hint
4.0 / 3, Math.PI, Math.round.
Answer
import java.util.Scanner;
class Sphere
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Radius: ");
double r = sc.nextDouble();
double vol = 4.0 / 3 * Math.PI * Math.pow(r, 3);
double sa = 4 * Math.PI * r * r;
System.out.println("Volume = " + Math.round(vol));
System.out.println("Surface area = " + Math.round(sa));
}
}
Trace with r = 3: volume = 36π ≈ 113.097 → 113; surface area = 36π ≈ 113.097 → 113. (Writing 4 / 3 would give 1 and a wrong volume.)Q9 · 2 marks · Very short answerBoard level
Why does Math.pow(2, 3) print 8.0 and not 8?
Hint
Return type.
Answer
Because Math.pow() always returns a double, so the result 8 is printed as 8.0.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Package of Math?Show answer
java.lang
2.Math.ceil(-3.8)?Show answer
-3.0
3.Math.round(2.5)?Show answer
3
4.Range of Math.random()?Show answer
0.0 inclusive to 1.0 exclusive.
5.Return type of Math.round(double)?Show answer
long
Best order to study it
- java.lang and calling static Math methods.
- pow, sqrt, cbrt.
- ceil, floor, round with negatives.
- abs, max, min and nesting.
- random() ranges.
- Java expressions from formulas.
Quick revision checklist
The night before the exam: can you do each of these without looking?
- Math is in java.lang (no import).
- pow, sqrt, cbrt, ceil, floor, random return double.
- round returns long (for double); .5 goes up: round(-2.5) = -2.
- abs/max/min keep the argument type (double if mixed).
- Random a to b: (int)(Math.random() * (b - a + 1)) + a.
Mathematical Library Methods: frequently asked questions
Is Math.PI in the syllabus?
It is not in the method list, but it is a standard constant of the Math class and may be used in expressions; 22.0 / 7 is also accepted.
What does Math.sqrt(-4) give?
NaN (not a number), since real square roots of negatives do not exist.
Does Math.round give a double?
No, it returns long (for a double argument), so Math.round(4.6) prints 5.
Based on: CISCE ICSE 2027 Computer Applications syllabus; CISCE Analysis of Pupil Performance ICSE 2025: Computer Applications (with the 2025 board paper)