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
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
Explanation: None.
3. Which of these method returns the remainder of dividend / divisor?
a) remainder()
b) getRemainder()
c) CSIremainder()
d) IEEEremainder()
View Answer
Explanation: IEEEremainder() returns the remainder of dividend / divisor.
4. Which of these method converts radians to degrees?
a) toRadian()
b) toDegree()
c) convertRadian()
d) converDegree()
View Answer
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
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 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
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?
class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.toDegrees(x);
System.out.print(y);
}
}
a) 0
b) 179
c) 180
d) 360
View Answer
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:
$ javac Output.java $ java Output 179
8. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.toRadians(x);
System.out.print(y);
}
}
a) 0
b) 3
c) 3.0
d) 3.1
View Answer
Explanation: None.
Output:
$ javac Output.java $ java Output 0
9. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
double x = 102;
double y = 5;
double z = Math.IEEEremainder(x, y);
System.out.print(z);}
}
}
a) 0
b) 1
c) 2
d) 3
View Answer
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?
class Output
{
public static void main(String args[])
{
int y = double z = Math.random();
System.out.print(y);
}
}
a) Yes
b) No
c) Compiler Dependent
d) Operating System Dependent
View Answer
Explanation: There is no relation between random numbers generated previously in Java.
Sanfoundry Global Education & Learning Series Java Programming Language.
- Practice BCA MCQs
- Practice Information Technology MCQs
- Practice Programming MCQs
- Apply for Java Internship
- Check Programming Books