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

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

Answer: a
Explanation: ciel(double X) returns the smallest whole number greater than or equal to variable X.

3. Which of these method return a largest whole number less 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: b
Explanation: double floor(double X) returns a largest whole number less than or equal to variable X.

4. Which of these method is a rounding function of Math class?
a) max()
b) min()
c) abs()
d) rint()
View Answer

Answer: d
Explanation: rint() rounds up a variable to nearest integer.

5. Which of these class contains only floating point functions?
a) Math
b) Process
c) System
d) Object
View Answer

Answer: a
Explanation: Math class contains all the floating point functions that are used for geometry, trigonometry, as well as several general purpose methods. Example : sin(), cos(), exp(), sqrt() etc.

6. Which of function return absolute value of a variable?
a) abs()
b) absolute()
c) absolutevariable()
d) None of the mentioned
View Answer

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

7. What is the output of this program?

  1.     class A {
  2.          int x;
  3.          int y;
  4.          void display() {
  5.               System.out.print(x + " " + y);
  6.          }
  7.     }
  8.     class Output {
  9.          public static void main(String args[]) {
  10.              A obj1 = new A();
  11.              A obj2 = new A();
  12.              obj1.x = 1;
  13.              obj1.y = 2;
  14.              obj2 = obj1.clone();
  15.              obj1.display();
  16.              obj2.display();
  17.         }
  18.     }

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

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

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.abs(x);
  5.              System.out.print(y);
  6.         }
  7.     }

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

Answer: b
Explanation: None.
Output:
$ javac Output.java
$ java Output
3

9. 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.ceil(x);
  5.              System.out.print(y);
  6.         }
  7.     }

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

Answer: d
Explanation: ciel(double X) returns the smallest whole number greater than or equal to variable x.
Output:
$ javac Output.java
$ java Output
4

10. 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.floor(x);
  5.              System.out.print(y);
  6.         }
  7.     }

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

Answer: d
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.

About

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.


Sanfoundry Training Center of Excellence (CoE)

Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.







Sanfoundry Internships
Subscribe Newsletter & Posts
Follow Manish & Sanfoundry