This section of our 1000+ Java MCQs focuses on rounding functions in Java Programming Language.
1. Which of these class provides various types of rounding functions?
a) Math
b) Process
c) System
d) Object
View Answer
Explanation: None.
2. Which of these methods return a smallest whole number greater than or equal to variable X?
a) double ceil(double X)
b) double floor(double X)
c) double max(double X)
d) double min(double X)
View Answer
Explanation: ceil(double X) returns the smallest whole number greater than or equal to variable X.
3. Which of these method returns a largest whole number less than or equal to variable X?
a) double ceil(double X)
b) double floor(double X)
c) double max(double X)
d) double min(double X)
View Answer
Explanation: double floor(double X) returns a largest whole number less than or equal to variable X.
4. Which of function return absolute value of a variable?
a) abs()
b) absolute()
c) absolutevariable()
d) none of the mentioned
View Answer
Explanation: abs() returns the absolute value of a variable.
5. What will be the output of the following Java code?
class A
{
int x;
int y;
void display()
{
System.out.print(x + " " + y);
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
A obj2 = new A();
obj1.x = 1;
obj1.y = 2;
obj2 = obj1.clone();
obj1.display();
obj2.display();
}
}
a) 1 2 0 0
b) 1 2 1 2
c) 0 0 0 0
d) System Dependent
View Answer
Explanation: clone() method of object class is used to generate duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2.
Output:
$ javac Output.java $ java Output 1 2 1 2
6. What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.abs(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 3
7. What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.ceil(x);
System.out.print(y);
}
}
a) 0
b) 3
c) 3.0
d) 4
View Answer
Explanation: ciel(double X) returns the smallest whole number greater than or equal to variable x.
Output:
$ javac Output.java $ java Output 4
8. What will be the output of the following Java code?
class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.floor(x);
System.out.print(y);
}
}
a) 0
b) 3
c) 3.0
d) 4
View Answer
Explanation: double floor(double X) returns a largest whole number less than or equal to variable X. Here the smallest whole number less than 3.14 is 3.
Output:
$ javac Output.java $ java Output 3
Sanfoundry Global Education & Learning Series Java Programming Language.
- Apply for Java Internship
- Apply for Computer Science Internship
- Check Java Books
- Practice BCA MCQs
- Practice Programming MCQs