Skip to content
Computer ApplicationsICSE Class 10 · Mathematical Library Methods

Java Math Class Methods: Return Types, Negative Cases and Expressions (ICSE Class 10)

Updated 17 October 2026 · Fact-checked

Math is a class of java.lang, so no import is needed. pow(x, y), sqrt(x), cbrt(x), ceil(x) and floor(x) return double; round(x) returns a long for a double argument; abs, max and min return the type of their arguments; random() returns a double from 0.0 up to but not including 1.0. ceil rounds towards bigger numbers, floor towards smaller numbers, and round gives the nearest whole number with halves going up.

Floor always moves left to the smaller whole number, ceil moves right to the bigger one, and round picks the nearer one (green ring); halves go up.

Illustration drawn for QuestionBuddy.

Understand Math Class Methods: Values, Return Types and Expressions

Where Math lives. Math belongs to the package java.lang, which Java imports by itself. Its methods are static, so you call them with the class name: Math.sqrt(25).

Methods in the syllabus and what they return

  • Math.pow(x, y): x raised to the power y, as a double. Math.pow(2, 5) is 32.0.
  • Math.sqrt(x): square root, double. Math.sqrt(81) is 9.0.
  • Math.cbrt(x): cube root, double. Math.cbrt(64) is 4.0.
  • Math.ceil(x): the smallest whole number not less than x, as a double. ceil(4.2) is 5.0; ceil(-4.2) is -4.0.
  • Math.floor(x): the largest whole number not greater than x, as a double. floor(4.8) is 4.0; floor(-4.2) is -5.0.
  • Math.round(x): the nearest whole number, as a long (no decimal point). It equals floor(x + 0.5): round(4.5) is 5, round(-4.5) is -4, round(4.4) is 4, round(-4.6) is -5.
  • Math.abs(a): absolute value, same type as a. abs(-7) is 7, abs(-7.5) is 7.5.
  • Math.max(a, b) and Math.min(a, b): larger or smaller; the result has the wider type of the two arguments (max(4, 9.5) is 9.5).
  • Math.random(): a double r with 0.0 <= r < 1.0.

Random numbers in a range. To get a whole number from low to high inclusive, use (int)(Math.random() * (high - low + 1)) + low. For a dice: (int)(Math.random() * 6) + 1 gives 1 to 6, since the cast cuts the fraction of a value between 0.0 and 5.999...

Writing formulas as Java expressions. Use Math.pow for powers and Math.sqrt for roots, and put brackets to control precedence. Watch for int division: write r / 100.0 or declare r as double. For example hypotenuse is Math.sqrt(a * a + b * b).

Output form. A method that returns double prints with a decimal point (Math.pow(2, 3) prints 8.0); round prints without.

Math Class Methods: Values, Return Types and Expressions: key facts

Return types
pow, sqrt, cbrt, ceil, floordouble
round(double)long
abs, max, mintype of the arguments
randomdouble
Check the type to know whether a decimal point is printed.
Ceil, floor and round
ceilnext whole number upward
floornext whole number downward
roundfloor(x + 0.5)
ceil(-4.2) = -4.0, floor(-4.2) = -5.0, round(-4.5) = -4.
Random in a range
  • count = high - low + 1
  • (int)(Math.random() times count) + low
  • Dice: count is 6, so the range is 1 to 6
random() is below 1.0, so the highest value is reachable only after +low.
Formulas as code
HypotenuseMath.sqrt(Math.pow(a, 2) + Math.pow(b, 2))
PowerMath.pow(x, n)
Compound amountp multiplied by Math.pow(1 + r / 100, n), with r double
With int r, r / 100 is 0 for r below 100.

How to answer Math Class Methods: Values, Return Types and Expressions questions

Use this routine for output and expression questions on Math.

  1. 1Evaluate the innermost method call first and write its value with the correct type (a decimal point for double results).
  2. 2For ceil, floor and round on negative numbers, think on the number line: ceil goes right, floor goes left.
  3. 3Apply operator precedence on the results: multiply and divide before add and subtract.
  4. 4Decide the type of the final value: double if any part is double, long for round of a double.
  5. 5For a formula, translate each power and root to a Math method and watch for int division.

Math Class Methods: Values, Return Types and Expressions in real life

The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Ceil for packing

Suppose a stationery shop packs 12 pencils in a box and a customer wants 50 pencils.

How many boxes are needed? Write the Java expression.

Try it first, then show the solutionSolution
  1. 50 / 12.0 = 4.1666..., and a part of a box still needs a whole box.
  2. Math.ceil(50 / 12.0) is 5.0 boxes.

Answer: 5 boxes: Math.ceil(50 / 12.0) gives 5.0.

Memory hook: Ceil to cover the leftover.

Random for a lucky draw

Imagine a school lucky draw where ticket numbers run from 1 to 100 and the computer picks one.

Write the expression that picks a ticket number.

Try it first, then show the solutionSolution
  1. low = 1, high = 100, so the count of values is 100 - 1 + 1 = 100.
  2. (int)(Math.random() * 100) + 1 gives 1 to 100.

Answer: (int)(Math.random() * 100) + 1

Memory hook: random x count, cast, then add low.

Tricks to remember Math Class Methods: Values, Return Types and Expressions

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • Ceil up, floor down

    A ceiling is above you (up); a floor is below you (down). This holds for negative numbers too.

    Use it when: ceil and floor on negative values.

  • Round = floor + 0.5

    round(x) is floor(x + 0.5), so -4.5 goes to -4.

    Use it when: Halves in round.

  • Double with a dot

    If the method returns double, print shows .0; round shows none.

    Use it when: Exact output form.

Math Class Methods: Values, Return Types and Expressions: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: Plain values · 2 marks · Short answerBoard level

Write the output:

System.out.println(Math.pow(2, 5));
System.out.println(Math.sqrt(81));
System.out.println(Math.cbrt(64));
System.out.println(Math.abs(-12));
Try it first, then show the solutionSolution
  1. pow, sqrt and cbrt return double: 32.0, 9.0 and 4.0. (1 mark)
  2. abs of an int argument returns an int: 12, with no decimal point. (1 mark)

Answer: 32.0
9.0
4.0
12

Example 2: Ceil, floor and round on both signs · 3 marks · Short answerHarder board level

Write the output:

System.out.println(Math.ceil(7.5));
System.out.println(Math.floor(7.5));
System.out.println(Math.round(7.5));
System.out.println(Math.ceil(-7.5));
System.out.println(Math.floor(-7.5));
System.out.println(Math.round(-7.5));
Try it first, then show the solutionSolution
  1. For 7.5: ceil is 8.0, floor is 7.0, round is floor(8.0) = 8. (1 mark)
  2. For -7.5: ceil is -7.0 (upward on the number line), floor is -8.0. (1 mark)
  3. round(-7.5) = floor(-7.5 + 0.5) = floor(-7.0) = -7, printed without a decimal point. (1 mark)

Answer: 8.0
7.0
8
-7.0
-8.0
-7

Example 3: Expression with several methods · 3 marks · Short answerHarder board level

Find the output:

System.out.println(Math.pow(3, 2) + Math.sqrt(16) * 2 - Math.abs(-5));
System.out.println(Math.max(Math.min(8, 3), 5));
Try it first, then show the solutionSolution
  1. pow(3,2) = 9.0, sqrt(16) = 4.0, abs(-5) = 5. (1 mark)
  2. Multiplication first: 4.0 * 2 = 8.0; then 9.0 + 8.0 - 5 = 12.0. (1 mark)
  3. min(8, 3) = 3 and max(3, 5) = 5 (int arguments give an int). (1 mark)

Answer: 12.0
5

Example 4: Case study: formulas as Java expressions · 4 marks · Case-basedHOTS / competency

A student must convert formulas to Java. All variables are double except n (int).
(i) Hypotenuse h of a right-angled triangle with sides a and b. (1)
(ii) Amount A = P (1 + R/100)^n. (1)
(iii) A random whole number from 10 to 20 inclusive. (1)
(iv) Find the values for a = 3, b = 4 and for P = 800.0, R = 50.0, n = 2. (1)

Try it first, then show the solutionSolution
  1. (i) double h = Math.sqrt(a * a + b * b);
  2. (ii) double A = P * Math.pow(1 + R / 100, n);
  3. (iii) Count of values = 20 - 10 + 1 = 11: int x = (int)(Math.random() * 11) + 10;
  4. (iv) h = sqrt(9 + 16) = sqrt(25) = 5.0. R / 100 = 0.5, 1 + 0.5 = 1.5, 1.5 squared = 2.25, A = 800.0 * 2.25 = 1800.0.

Answer: (i) Math.sqrt(a * a + b * b) (ii) P * Math.pow(1 + R / 100, n) (iii) (int)(Math.random() * 11) + 10 (iv) h = 5.0, A = 1800.0

Example 5: Cast, round and floor compared · 3 marks · Short answerHarder board level

Write the output:

double x = 6.7, y = -6.7;
System.out.println((int) x + " " + Math.round(x) + " " + Math.floor(x));
System.out.println((int) y + " " + Math.round(y) + " " + Math.ceil(y));
Try it first, then show the solutionSolution
  1. For x = 6.7: (int) cuts to 6; round gives 7; floor gives 6.0. (1 mark)
  2. For y = -6.7: (int) cuts towards zero to -6; round = floor(-6.2) = -7; ceil(-6.7) = -6.0. (1 mark)
  3. Each println joins its three values with spaces. (1 mark)

Answer: 6 7 6.0
-6 -7 -6.0

Where students lose marks in Math Class Methods: Values, Return Types and Expressions

The slips examiners see most often, and what to write instead.

  • Mistake: Printing ceil or floor results without .0

    They return double, so the output shows a decimal point.

    Wrong working

    Math.ceil(4.2) = 5

    Right working

    Math.ceil(4.2) = 5.0

    Do this: Add .0 for all methods except round and integer abs, max, min.

    Usually costs: 1 mark

  • Mistake: Rounding -4.5 to -5

    round(x) = floor(x + 0.5), so halves go upward, towards the larger number.

    Wrong working

    Math.round(-4.5) = -5

    Right working

    Math.round(-4.5) = -4

    Do this: Add 0.5 and take floor.

    Usually costs: 1 mark

  • Mistake: Writing x^2 or x**2 in Java

    Java has no power operator; ^ is another operator.

    Wrong working

    area = 3.14 * r ^ 2;

    Right working

    area = 3.14 * Math.pow(r, 2);

    Do this: Use Math.pow or r * r.

    Usually costs: 1 mark

Exam tips

  • Write the decimal point for double results; examiners check it.
  • For a range [low, high], count values as high - low + 1 and write the three parts of the expression in order.
  • Do ceil and floor on the number line, especially for negatives.
  • No import is needed for Math; do not write one.

Practice questions on Math Class Methods: Values, Return Types and Expressions

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    The value of Math.ceil(4.2) is:
    (a) 4.0 (b) 5.0 (c) 4 (d) 5

    Hint

    ceil returns double.

    Answer

    (b) 5.0

  2. Q2 · 1 mark · Very short answerBoard level

    What is the return type of Math.pow(x, y)?

    Hint

    A decimal point appears in the output.

    Answer

    double

  3. Q3 · 2 marks · Short answerHarder board level

    Write the output:

    System.out.println(Math.round(2.5) + " " + Math.round(-2.5) + " " + Math.round(3.49));
    Hint

    round(x) = floor(x + 0.5).

    Answer

    3 -2 3

  4. Q4 · 3 marks · Short answerHarder board level

    Write a Java expression that simulates the throw of a dice (a whole number from 1 to 6). Explain why the cast and the +1 are needed.

    Hint

    random() is between 0.0 and 1.0.

    Answer

    (int)(Math.random() * 6) + 1. Math.random() * 6 lies from 0.0 up to just below 6.0; the cast (int) cuts the fraction and leaves 0 to 5; adding 1 shifts the range to 1 to 6.

  5. Q5 · 1 mark · Assertion-reasonHOTS / competency

    Assertion (A): Math.floor(-3.2) gives -4.0.
    Reason (R): floor returns the largest whole number that is not greater than its argument.
    (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.

    Hint

    Which whole numbers are not greater than -3.2?

    Answer

    (a) Both are true and R explains A: -4 is the largest whole number not greater than -3.2.

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. 1.Which package contains Math?Show answer

    java.lang

  2. 2.What is Math.cbrt(27)?Show answer

    3.0

  3. 3.What is the range of Math.random()?Show answer

    0.0 up to but not including 1.0.

  4. 4.What is Math.floor(-2.1)?Show answer

    -3.0

  5. 5.What does Math.round(4.5) give?Show answer

    5

  6. 6.What is the type of Math.max(4, 9.5)?Show answer

    double (9.5).

Math Class Methods: Values, Return Types and Expressions: frequently asked questions

What is the difference between Math.round and casting to int?

A cast cuts the fraction towards zero; Math.round gives the nearest whole number, with halves going up.

Why does Math.pow(2, 3) print 8.0?

pow returns a double, so it prints with a decimal point.

Do I need to import Math?

No. It is in java.lang, which is imported automatically.