Java Multiple Choice Questions & Answers on Java.lang package Miscellaneous Math Methods & StrictMath Class for Freshers

1. Which of these class contains all the methods present in Math class?

a) SystemMath
b) StrictMath
c) Compiler
d) ClassLoader
Answer: b

Explanation: SystemMath class defines 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
3. Which of these method returns the remainder of dividend / devisor?

a) remainder()
b) getRemainder()
c) CSIremainder()
d) IEEEremainder()
Answer: d

Explanation: IEEEremainder() returns the remainder of dividend / devisor.
4. Which of these method converts radians to degrees?

a) toRadian()
b) toDegree()
c) convertRadian()
d) converDegree()
Answer: b
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

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.
6. Which of these method return 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

Explanation: ciel(double X) returns the smallest whole number greater than or equal to variable X.
7. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             double x = 3.14;  
  4.             int y = (int) Math.toDegrees(x);
  5.             System.out.print(y);
  6.         }
  7.     }
a) 0
b) 179
c) 180
d) 360
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.
8. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             double x = 3.14;  
  4.             int y = (int) Math.toRadians(x);
  5.             System.out.print(y);
  6.         }
  7.     }
a) 0
b) 3
c) 3.0
d) 3.1
Answer: a
9. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             double x = 102;
  4.             double y = 5;
  5.             double z = Math.IEEEremainder(x, y);
  6.             System.out.print(z);}
  7.         }
  8.     }
a) 0
b) 1
c) 2
d) 3
Answer: b

Explanation: IEEEremainder() returns the remainder of dividend / devisor. Here dividend is 102 and devisor is 5 therefore remainder is 2. It is similar to modulus – ‘%’ operator of C/C++ language.
10. Will this program generate same output is executed again?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             int y = double z = Math.random();
  4.             System.out.print(y);
  5.         }
  6.     }
a) Yes
b) No
c) Compiler Dependent
d) Operating System Dependent
Answer: b

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

Related

Multiple Choice Questions 8871791016273723456

Post a Comment

emo-but-icon

item