IndiaBIX
IndiaBIX
Start typing & press "Enter" or "ESC" to close
  • Home
  • Jobs
  • Results
  • Current Affairs
  • GK
  • Online Test
  • HR Interview
  • BLOG

What is the value of "d" after this line of code has been executed? double d = Math.round ( 2.5 + Math.random() );

  • Home
  • Computer Science & Engineering
  • Java Programming Questions and Answers
  • Java.lang Class - General Questions
  • Discuss - 1362
1. 

What is the value of "d" after this line of code has been executed?

double d = Math.round ( 2.5 + Math.random() );

[A]. 2
[B]. 3
[C]. 4
[D]. 2.5

Answer: Option B

Explanation:

The Math.random() method returns a number greater than or equal to 0 and less than 1 . Since we can then be sure that the sum of that number and 2.5 will be greater than or equal to 2.5 and less than 3.5, we can be sure that Math.round() will round that number to 3. So Option B is the answer.

Workspace Report
Leave a Comment

Computer Science & Engineering :: Java Programming Questions and Answers : More Exercises

  • Language Fundamentals - General Questions
  • Operators and Assignments - Finding the output
  • Exceptions - Finding the output
  • Inner Classes - General Questions
  • Height and Distance - Garbage Collections
  • Java.lang Class - General Questions
  • Declarations and Access Control - General Questions
  • Flow Control - General Questions
  • Objects and Collections - General Questions
  • Threads - General Questions
  • Assertions - Finding the output

Questions & Answers

Aptitude Chemical Engineering Civil Engineering Computer Science & Engineering Current Affairs Data Interpretation Electrical & Electronics Engineering Electronics & Communication Engineering General Knowledge Logical Reasoning Mechanical Engineering Non Verbal Reasoning Verbal Ability Verbal Reasoning

Interviews

HR Interview

Jobs

Sarkari Jobs

Results

Rojgar ResultSarkari Result

Admission

Admission 2023

Admit Card

Admit Card 2023

Answer Key

Answer Key 2023
copyright
Privacy Policy
© 2025 IndiaBIX. All Rights Reserved.

Report