File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes ques. from JWhiz seems to have a wrong answer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "ques. from JWhiz seems to have a wrong answer" Watch "ques. from JWhiz seems to have a wrong answer" New topic
Author

ques. from JWhiz seems to have a wrong answer

neha jain
Greenhorn

Joined: Oct 11, 2001
Posts: 27
hi friends,
following is a ques. from jwiz.
What will the result be for the following block of code when it is executed?
int i = 3;
int j = 0;
float k = 3.2F;
long m = -3;
if (Math.ceil(i) < Math.floor(k))
if (Math.abs(i) == m)
System.out.println(i);
else
System.out.println(j);
else
System.out.println(Math.abs(m) + 1);
the correct answer given for this is that output wiil b 4.
but what i guess is that it should give a compile time error,as ceil method takes only double as an argument.if we pass integer it will give a compile time error.
can anybody help me.
neha.
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

Originally posted by neha jain:
the correct answer given for this is that output wiil b 4.
but what i guess is that it should give a compile time error,as ceil method takes only double as an argument.if we pass integer it will give a compile time error.
can anybody help me.
neha.

The correct answer is 4. No compile error in this case. It is *always* possible to pass an integer to a method which takes double as per conversion rules. Conversion rules for primitives take place in -

    * Assignemnt
    * Method Calls
    * Arithetic operations

    HTH,
    - Manish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ques. from JWhiz seems to have a wrong answer