ICSE · Class 9 · Computer Applications

Class 9 Mathematical Library Methods Mock Test (ICSE)

6 practice questions from Mathematical Library Methods, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.

Topics in Mathematical Library Methods

  • Math.pow and Math.sqrt
  • Math.abs, Math.max and Math.min
  • Math.round, Math.ceil and Math.floor
  • Math.random
  • Using Math methods in expressions

Mathematical Library Methods practice questions with answers

  1. Q1Multiple choice1 mark
    What is the output of the expression `int x = (int)Math.max(Math.min(10, 15), Math.abs(-12));`?
    1. (a)1212
    2. (b)1010
    3. (c)1515
    4. (d)−12-12
    Show answer and step marks
    1. Correct option: (a) 1212+1
    Answer: (a)
  2. Q2Multiple choice1 mark
    A square sports ground has an area of 144 m². Which Java expression gives the length of one side in metres?
    1. (a)Math.sqrt(144)Math.sqrt(144)
    2. (b)Math.pow(144,2)Math.pow(144, 2)
    3. (c)Math.sqrt(144∗2)Math.sqrt(144 * 2)
    4. (d)Math.round(144/2)Math.round(144 / 2)
    Show answer and step marks
    1. Correct option: (a) Math.sqrt(144)Math.sqrt(144)+1
    Answer: (a)
  3. Q3Short answer3 marks
    An orchard packs fruit into boxes that each hold 10 fruit. A program stores the number of boxes needed as shown below. int fruit = 43; double boxes = fruit / 10.0; (a) Find the value of Math.floor(boxes). [1] (b) Find the value of Math.ceil(boxes). [1] (c) Find the value of Math.round(boxes). [1]
    Show answer and step marks
    1. boxes = 43 / 10.0 = 4.3, so Math.floor(4.3) gives the largest integer not greater than 4.3, which is 4.+1
    2. Math.ceil(4.3) gives the smallest integer not less than 4.3, which is 5.+1
    3. Math.round(4.3) rounds to the nearest integer, and 0.3 is less than 0.5, so the value is 4.+1
    Answer: (a) 4; (b) 5; (c) 4
  4. Q4Short answer3 marks
    A dice game program contains the statement int r = (int)(Math.random()*6)+1; to simulate the throw of a dice. (a) State the range of values that Math.random() returns. [1] (b) State the set of values that the variable r can take. [1] (c) State the value of r when Math.random() returns 0.99. [1]
    Show answer and step marks
    1. Math.random() returns a double x with 0.0≤x<1.00.0 \le x < 1.0+1
    2. Math.random()*6 lies between 0.0 and less than 6.0; the cast keeps the integer part 0 to 5, and adding 1 gives r from 1 to 6+1
    3. 0.99×6=5.940.99 \times 6 = 5.94; cast gives 5; adding 1 gives r = 6+1
    Answer: (a) 0.0≤x<1.00.0 \le x < 1.0 (0.0 included, 1.0 excluded); (b) 1, 2, 3, 4, 5, 6; (c) 6
  5. Q5Long answer4 marks
    Write a Java program to accept the lengths of the three sides of a triangle (aa, bb, and cc) as double values using the Scanner class. Calculate and display the area of the triangle using Heron's formula: Area=s(s−a)(s−b)(s−c)\text{Area} = \sqrt{s(s - a)(s - b)(s - c)} where s=a+b+c2s = \frac{a + b + c}{2}. Use the appropriate Math library method in your expression.
    Show answer and step marks
    1. Correct import statement (`import java.util.Scanner;`), class declaration, and `main` method setup with `Scanner` initialization.+1
    2. Correctly reading three double values for sides and computing the semi-perimeter s=(a+b+c)/2.0s = (a + b + c) / 2.0.+1
    3. Using `Math.\sqrt{}` to evaluate the Heron's formula expression `Math.s×(s−a)×(s−b)×(s−c)\sqrt{s × (s - a) × (s - b) × (s - c)}`.+1
    4. Printing the computed area cleanly using `System.out.println()`.+1
    Answer: import java.util.Scanner; public class HeronArea { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the three sides: "); double a = sc.nextDouble(); double b = sc.nextDouble(); double c = sc.nextDouble(); double s = (a + b + c) / 2.0; double area = Math.s×(s−a)×(s−b)×(s−c)\sqrt{s × (s - a) × (s - b) × (s - c)}; System.out.println("Area of the triangle = " + area); } } (The sides are assumed to form a valid triangle.)
  6. Q6Long answer4 marks
    Write a program in Java using the `Scanner` class to accept the coordinates of a point (x,y)(x, y) as `double` values. Calculate and display its distance from the origin using the formula: Distance=Math.pow(x,2)+Math.pow(y,2)\text{Distance} = \sqrt{\text{Math.pow}(x, 2) + \text{Math.pow}(y, 2)} Use appropriate `Math` library methods for your calculations.
    Show answer and step marks
    1. Importing java.util.Scanner and setting up the class and main method structure.+1
    2. Accepting input for x and y coordinates correctly as double values using Scanner.+1
    3. Applying the mathematical expression using Math.pow() and Math.\sqrt{} methods.+1
    4. Displaying the calculated distance with an appropriate output message.+1
    Answer: import java.util.Scanner; public class Distance { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter x and y: "); double x = sc.nextDouble(); double y = sc.nextDouble(); double d = Math.Math.pow(x,2)+Math.pow(y,2)\sqrt{Math.pow(x, 2) + Math.pow(y, 2)}; System.out.println("Distance from the origin = " + d); } }

Take a full Mathematical Library Methods test

PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.

  • 15 min10 marks
  • 30 min20 marks
  • 1.5 hr40 marks
  • 3 hr80 marks
See a sample marked answer sheet

Get your Mathematical Library Methods answers marked

Sign in, pick this chapter and a length, write the test on paper and get every step marked.

Sign in to take this test

More Class 9 Computer Applications mock tests