Java MCQs on miscellaneous Math methods & StrictMath class of Java Programming Language.
1. Which of these class contains all the methods present in Math class? Answer: b 2. Which of these method return a pseudorandom number? Answer: b 3. Which of these method returns the remainder of dividend / divisor? Answer: d 4. Which of these method converts radians to degrees? Answer: b 5. toRadian() and toDegree() methods were added by which version of Java? Answer: c 6. Which of these method returns a smallest whole number greater than or equal to variable X? Answer: a 7. What will be the output of the following Java program? a) 0 8. What will be the output of the following Java program? a) 0 9. What will be the output of the following Java program? a) 0 10. Will this Java program generate same output is executed again? a) Yes Answer: b
a) SystemMath
b) StrictMath
c) Compiler
d) ClassLoader
Clarification: SystemMath class defines a complete set of mathematical methods that are parallel those in Math class. The difference is that the StrictMath version is guaranteed to generate precisely identical results across all Java implementations.
a) rand()
b) random()
c) randomNumber()
d) randGenerator()
Clarification: None.
a) remainder()
b) getRemainder()
c) CSIremainder()
d) IEEEremainder()
Clarification: IEEEremainder() returns the remainder of dividend / divisor.
a) toRadian()
b) toDegree()
c) convertRadian()
d) converDegree()
Clarification: None.
a) Java 1.0
b) Java 1.5
c) Java 2.0
d) Java 3.0
Clarification: toRadian() and toDegree() methods were added by Java 2.0 before that there was no method which could directly convert degree into radians and vice versa.
a) double ciel(double X)
b) double floor(double X)
c) double max(double X)
d) double min(double X)
Clarification: ciel(double X) returns the smallest whole number greater than or equal to variable X.
class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.toDegrees(x);
System.out.print(y);
}
}
b) 179
c) 180
d) 360
Clarification: 3.14 in degree 179.9087. We usually take it to be 180. Buts here we have type casted it to integer data type hence 179.
Output:
$ javac Output.java
$ java Output
179
class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.toRadians(x);
System.out.print(y);
}
}
b) 3
c) 3.0
d) 3.1
Clarification: None.
Output:
$ javac Output.java
$ java Output
0
class Output
{
public static void main(String args[])
{
double x = 102;
double y = 5;
double z = Math.IEEEremainder(x, y);
System.out.print(z);}
}
}
b) 1
c) 2
d) 3
Clarification: IEEEremainder() returns the remainder of dividend / divisor. Here dividend is 102 and divisor is 5 therefore remainder is 2. It is similar to modulus – ‘%’ operator of C/C++ language.
Output:
$ javac Output.java
$ java Output
2
class Output
{
public static void main(String args[])
{
int y = double z = Math.random();
System.out.print(y);
}
}
b) No
c) Compiler Dependent
d) Operating System Dependent
Clarification: There is no relation between random numbers generated previously in Java.