Java Questions & Answers – Java.lang – Miscellaneous Math Methods & StrictMath Class

This section of our 1000+ Java MCQs focuses 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
View Answer

Answer: b
Explanation: 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()
View Answer

Answer: b
Explanation: None.

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

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

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

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

Answer: c
Explanation: 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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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)
View Answer

Answer: a
Explanation: 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?

advertisement
  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
View Answer

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

advertisement
$ 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
View Answer

Answer: a
Explanation: 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
View Answer

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

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

Sanfoundry Global Education & Learning Series – Java Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.