In: Computer Science
You do not need to import the Math class into your Java program to use methods or constants in it.
Group of answer choices
True
False
The answer is True, that is because the Math class is in the global standard namespace and all the methods and constants inside are public static. So, you can directly access them using the Math class name. Example:
Math.random()
Here is a small code example to understand it better:
public class MyClass {
public static void main(String args[]) {
System.out.println("Some random value: " + Math.random());
System.out.println("Square root of 36: " + Math.sqrt(36));
}
}
Even though we haven't imported the Math class explicitly here, the program would compile and run succesfully. The first print statement will print a random number and the second print statement will print the square root of 36, which is 6.