Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Explain this question........ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Explain this question........" Watch "Explain this question........" New topic
Author

Explain this question........

Daniel Pearl
Greenhorn

Joined: Apr 13, 2007
Posts: 3
Please do not post questions from that source on this forum
[ April 17, 2007: Message edited by: Barry Gaunt ]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Correct answer E!


Right??

Regards,
cmbhatt


cmbhatt
megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Try this

import java.lang.Math.*;
public class Main
{
public static void main(String[] args)
{
double bar = -2.7;
int foo;
//int foo = (int) Math.max(3);
// foo = (int) Math.min(2);
foo = (int) Math.abs(bar);
System.out.println(foo);
foo = (int) Math.ceil(bar);
System.out.println(foo);
foo = (int) Math.floor(bar);
System.out.println(foo);
foo = (int) Math.round(bar);
System.out.println(foo);
}

}

Try substituting 2.7 and try again, try uncommenting the commented out lines and see what's the error message.

Give a thought to the outputs.

The correct answer for your question would be foo = (int) Math.floor(bar);
Tell me why
Hope this helps...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Explain this question........