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: Power and Square Root Calculation


Write a program to print:

  1. x to the power y
  2. the square root of y

The values of x and y are 81 and 3, respectively.

public class PowerAndSquareRoot {

    public static void main(String[] args) {

 

        int x = 81;

        int y = 3;

 

        // Calculations

        double power = Math.pow(x, y);

        double squareRoot = Math.sqrt(y);

 

        // Output

        System.out.println("x to the power y = " + power);

        System.out.println("Square root of y = " + squareRoot);

    }

}

Output

x to the power y = 531441.0
Square root of y = 1.7320508075688772

Explanation

  • Math.pow(x, y) calculates

                 813 = 53144181

  • Math.sqrt(y) calculates the square root of y

                √3 ≈ 1.732

Concepts Used

  • Math.pow() – power calculation
  • Math.sqrt() – square root calculation

📌 Formatted Output (Optional)

System.out.printf("x to the power y = %.0f\n", power);

System.out.printf("Square root of y = %.3f", squareRoot);