Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Mathematical Library Methods

Chapter 7

Mathematical Library Methods

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Using Mathematical Functions


13. Write the equivalent Java statements for the following, by using the mathematical functions:

i. Print the positive value of -999.

ii. Store the value -3375 in a variable and print its cube root.

iii. Store the value 999.99 in a variable and convert it into its closest integer that is greater than or equal to 999.99.

import java.util.Scanner;

 

public class MathFunctionsDemo {

    public static void main(String[] args) {

 

        // i. Print the positive value of -999

        int a = -999;

        System.out.println("Positive value of -999 = " + Math.abs(a));

 

        // ii. Store -3375 and print its cube root

        double b = -3375;

        System.out.println("Cube root of -3375 = " + Math.cbrt(b));

 

        // iii. Convert 999.99 to the closest integer greater than or equal to it

        double c = 999.99;

        System.out.println("Closest integer >= 999.99 = " + (int)Math.ceil(c));

    }

}

Output

Positive value of -999 = 999
Cube root of -3375 = -15.0
Closest integer >= 999.99 = 1000

Explanation

i. Positive value

  • Math.abs() returns the absolute (positive) value of a number.

ii. Cube root

  • Math.cbrt() calculates the cube root.
  • Cube root of -3375 = -15

iii. Closest integer greater than or equal to

  • Math.ceil() rounds a number upward.
  • Type casting to int converts the result to an integer.

Math Functions Used

Function Purpose

Math.abs()

Absolute value

Math.cbrt()

Cube root

Math.ceil()

Smallest integer ≥ number