- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Use static Import for sqrt() and pow() methods in class Math in Java

Static import means that the fields and methods in a class can be used in the code without specifying their class if they are defined as public static.

The Math class methods sqrt() and pow() in the package java.lang are static imported. A program that demonstrates this is given as follows:

## Example

import static java.lang.Math.sqrt; import static java.lang.Math.pow; public class Demo { public static void main(String args[]) { double num = 4.0; System.out.println("The number is: " + num); System.out.println("The square root of the above number is: " + sqrt(num)); System.out.println("The square of the above number is: " + pow(num, 2)); } }

## Output

The number is: 4.0 The square root of the above number is: 2.0 The square of the above number is: 16.0

Now let us understand the above program.

The Math class is not required along with the method sqrt() and pow() as static import is used for the java.lang package. The number num as well as its square root and square is displayed. A code snippet which demonstrates this is as follows:

double num = 4.0; System.out.println("The number is: " + num); System.out.println("The square root of the above number is: " + sqrt(num)); System.out.println("The square of the above number is: " + pow(num, 2));

- Related Questions & Answers
- Static import the Math Class Methods in Java
- Math class methods in Java Programming
- Math class methods in C#
- What are Class/Static methods in Java?
- Demonstrate Static Import in Java
- Declare static variables and methods in an abstract class in Java
- What is static import in Java?
- What are the differences between import and static import statements in Java?
- Differences between static and non-static methods in Java
- Class and Static Variables in Java
- Why static methods of parent class gets hidden in child class in java?
- Static methods vs Instance methods in Java
- Static class in Java
- Demonstrate static variables, methods and blocks in Java
- What are static methods in a Python class?

Advertisements