sarim raza

Ranch Hand

Posts: 232

posted 16 years ago

7. Given

double pi = Math.PI;

Which two are valid ways to round pi to an int?(Choose two.)

A.int p = pi;

B.int p = Math.round(pi);

C.int p = (int)Math.round(pi);

D.int p = (int)Math.min(pi + 0.5d);

E.int p = (int)Math.floor(pi + 0.5d);

//CORRECT ANSWER IS C AND E, WHY IS E CORRECT ??

WHAT IS THE d mean ?

double pi = Math.PI;

Which two are valid ways to round pi to an int?(Choose two.)

A.int p = pi;

B.int p = Math.round(pi);

C.int p = (int)Math.round(pi);

D.int p = (int)Math.min(pi + 0.5d);

E.int p = (int)Math.floor(pi + 0.5d);

//CORRECT ANSWER IS C AND E, WHY IS E CORRECT ??

WHAT IS THE d mean ?

Ashish Agarwal

Ranch Hand

Posts: 36

sonal gupta

Greenhorn

Posts: 4

Tom Tang

Ranch Hand

Posts: 133

sarim raza

Ranch Hand

Posts: 232

posted 16 years ago

thanks for the effort guys, but my question was WHY IS E CORRECT ?

i did not get an answer to that, i know how the floor works, but why is the value of pi, added to 0.5d, what is 0.5d, where does it come from , what does it represent ?

if it is a double value of 0.5, then after performing round, we would get 4 as a result and not 3, explain ?

i did not get an answer to that, i know how the floor works, but why is the value of pi, added to 0.5d, what is 0.5d, where does it come from , what does it represent ?

if it is a double value of 0.5, then after performing round, we would get 4 as a result and not 3, explain ?

Tom Tang

Ranch Hand

Posts: 133

sarim raza

Ranch Hand

Posts: 232

Tom Tang

Ranch Hand

Posts: 133

sunilkumar ssuparasmul

Ranch Hand

Posts: 142

posted 16 years ago

D is incorrect bcos Math.min(a,b) takes 2 arguments where a,b can be double , int ,long or float. but here it takes only one arguments..

HTH

sunil.s

------------------

"Winners don't do different things

They do things differently"

HTH

sunil.s

------------------

"Winners don't do different things

They do things differently"

"Winners don't do different things<br /> They do things differently"

It is sorta covered in the JavaRanch Style Guide. |