# Java Questions & Answers – Java.lang – Rounding Functions

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

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)

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)

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

Explanation: abs() returns the absolute value of a variable.

5. What will be the output of the following Java code?

Note: Join free Sanfoundry classes at Telegram or Youtube
1. `    class A `
2. `    {`
3. `         int x;`
4. `         int y;`
5. `         void display() `
6. `         {`
7. `              System.out.print(x + " " + y);`
8. `         }`
9. `    }`
10. `    class Output `
11. `    {`
12. `         public static void main(String args[]) `
13. `         {`
14. `             A obj1 = new A();`
15. `             A obj2 = new A();`
16. `             obj1.x = 1;`
17. `             obj1.y = 2;`
18. `             obj2 = obj1.clone();`
19. `             obj1.display();`
20. `             obj2.display();`
21. `         }`
22. `    }`

a) 1 2 0 0
b) 1 2 1 2
c) 0 0 0 0
d) System Dependent

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?

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

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

Explanation: None.
Output:

```\$ javac Output.java
\$ java Output
3```

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

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

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

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?

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

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

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.

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