250+ TOP MCQs on Java.lang – Miscellaneous Math Methods & StrictMath Class and Answers

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?
a) SystemMath
b) StrictMath
c) Compiler
d) ClassLoader

Answer: b
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.

2. Which of these method return a pseudorandom number?
a) rand()
b) random()
c) randomNumber()
d) randGenerator()

Answer: b
Clarification: None.

3. Which of these method returns the remainder of dividend / divisor?
a) remainder()
b) getRemainder()
c) CSIremainder()
d) IEEEremainder()

Answer: d
Clarification: IEEEremainder() returns the remainder of dividend / divisor.

4. Which of these method converts radians to degrees?
a) toRadian()
b) toDegree()
c) convertRadian()
d) converDegree()

Answer: b
Clarification: None.

5. toRadian() and toDegree() methods were added by which version of Java?
a) Java 1.0
b) Java 1.5
c) Java 2.0
d) Java 3.0

Answer: c
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.

6. Which of these method returns a smallest whole number greater than or equal to variable X?
a) double ciel(double X)
b) double floor(double X)
c) double max(double X)
d) double min(double X)

Answer: a
Clarification: ciel(double X) returns the smallest whole number greater than or equal to variable X.

7. What will be the output of the following Java program?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             double x = 3.14;  
  6.             int y = (int) Math.toDegrees(x);
  7.             System.out.print(y);
  8.         }
  9.     }

a) 0
b) 179
c) 180
d) 360

Answer: b
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

8. What will be the output of the following Java program?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             double x = 3.14;  
  6.             int y = (int) Math.toRadians(x);
  7.             System.out.print(y);
  8.         }
  9.     }

a) 0
b) 3
c) 3.0
d) 3.1

Answer: a
Clarification: None.
Output:

$ javac Output.java
$ java Output
0

9. What will be the output of the following Java program?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             double x = 102;
  6.             double y = 5;
  7.             double z = Math.IEEEremainder(x, y);
  8.             System.out.print(z);}
  9.          }
  10.     }

a) 0
b) 1
c) 2
d) 3

Answer: c
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

10. Will this Java program generate same output is executed again?

  1.     class Output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             int y = double z = Math.random();
  6.             System.out.print(y);
  7.         }
  8.     }

a) Yes
b) No
c) Compiler Dependent
d) Operating System Dependent

Answer: b
Clarification: There is no relation between random numbers generated previously in Java.

Leave a Reply

Your email address will not be published. Required fields are marked *