This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Could you explain me the answers for this

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)Given this code snippet:
: double a = 90.7;
: double b = method(a);
: System.out.println(b);
: If this snippet displays 90 in the standard output, what Math method did method() invoke?
:
: Select all valid answers.
: a)abs()
: b)min()
: c)floor()
: d)round()
: e)ceil()
:
: 2)Given this code snippet:
: double a = 14.9;
: double b = method(a);
: System.out.println(b);
: If this snippet displays 15.0 in the standard output, what Math method(s) could method() have invoke?
: Select the one right answer.
: a)ceil() and round()
: b)floor() and round()
: c)ceil() only
: d)floor() only
: e)round() only
: What could be the answers for this?will you please explain it.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CEIL (up, roof)
ceil returns the round off to integer double value which is greater than or equal to the argument (d) passed to ceil(double d) argument but close to Negative Infinity. It implies that if you have 14.9 as an argument then it means that int value greater than 14.7 may be 15, 16, 17, and so on so we have a set containing {15,16,17,18, .......Positive infinity}
Now choose the value from this set which is close to negative infinity which is 15.0 in double
FLOOR (down, you walk on floor)
Floor returns the round off to integer double value that is less than or equal to the value passed into the argument (d) of floor(double d) function and close to the Positive Infinity. It implies that if you have 90.7 the the integer values that are less than 90.7 are 90,89,88, and so on so we have set
{negative infinity ..........88,89,90}
Now choose the value which is close to the positive infinity so that value is 90.0 (double).
Round Off to close Integral value
round(14.9) = 15 (long value is returned)
Now you can answer the questions. Hope you will understand the difference.
 
simon
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Addition to the previous message
Remember the scale given below to understand above
Negative_Infinity .......-5, -3, -3, -2, -1, 0, 1,2,3,4,5,............Positive_Infinity
 
Meena
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks simon.I have clearly understood your
explanation.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Meena,
ceil will give u the next highest integer. eg. ceil(10.7)=11 ceil(-4.2)=-4
floor will give u the next lowest integer. eg. floor(10.7)=10 floor(-4.2)=-5
Best of luck......I gotta get studying i have my scjp exam this saturday.
Srini
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Meena and simon,
Your username does not comply with the JavaRanch Naming Policy.
Please read it and re-register.
Thank you very much for your cooperation

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Meena
Just wanted to just my 2 cents
Q1: The output should be 90.0
to qualify for floor() function
Q2: ceil() only output (15.0)
Ragu
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic