Determine output of the following program.
public class Test{
public static void main(String args[]){
System.out.println( Math.floor( Math.random( ) ) ) ;
}
}
public class Test{
public static void main(String args[]){
System.out.println( Math.floor( Math.random( ) ) ) ;
}
}
A. 1.0
B. 10.0
C. 0.0
D. 0.5
Answer: Option C
Solution(By Examveda Team)
random() is a static method defined in Math class.
Syntax: static double random()
random() always return a value in the range 0.0 <= Math.random() <1.0 So, taking floor function of any number between above range always yield 0.0.
Ex: Math.floor(0.958127101241...) = 0.0
Math.floor(0.05684865565...) = 0.0
What is a constructor in Java?
A. A special method to create instances of classes
B. A method used for mathematical calculations
C. A method to perform string manipulations
D. An exception handling mechanism
In Java, which method is automatically called when an object is created?
A. start()
B. main()
C. init()
D. constructor()
What is method overloading in Java?
A. Defining multiple methods with the same name in the same class
B. Calling methods from another class
C. Using methods to load data from a file
D. Running methods in parallel threads
Join The Discussion