aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ID:6 SCJP Question of the day : Saturday June 12 2010 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ID:6 SCJP Question of the day : Saturday June 12 2010" Watch "ID:6 SCJP Question of the day : Saturday June 12 2010" New topic
Author

ID:6 SCJP Question of the day : Saturday June 12 2010

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Source :- Sahil Rally Neuron's !!!



Tell Output, Compiler Error and Runtime error at each line of above code ???

Best Wishes !!!
Cheers!!!



Reference for rules:
http://www.coderanch.com/t/498524/java-programmer-SCJP/certification/ID-SCJP-day-Wednesday-June


SCJP 6.0 96%

(Connecting the Dots ....)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Hmm, good one, let me try
1->Infinity
2->Exception
3->compile time error
4->Infinity
5->-Infinity
6->-Infinity
7->Exception
8->Infinity
9->-Infinity
10->compile time error

(I hope not all are wrong )


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Larry Olson
Ranch Hand

Joined: Feb 03, 2009
Posts: 142
Good question. The principles to remember to be able to answer this question are:

- Division operation could be performed only on numeric values. Trying to divide non-numeric values will result in a compile time error
- Division of a integer value by zero will result in a RuntimeException (ArithmeticException of trying to divide by zero)
- Division of a floating type value by zero will result in infinity for non-zero numerator and NaN (Not a Number) if the numerator is 0

Hope that helps!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40


And don't forget...



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Larry Olson
Ranch Hand

Joined: Feb 03, 2009
Posts: 142
Hi Henry

System.out.println(0.0 / (-4.0));


Good. But there is no trick in that, right? i.e. it is assumed everyone understands that! May be that is the reason Sahil didn't include that in the posted code
Abhinav Yadav
Ranch Hand

Joined: Nov 08, 2009
Posts: 34

1). infinity
2). ArithmeticException
3). Compile time error
4). infinity
5). -infinity
6). -infinity
7). ArithmeticException
8). NaN(not a number)
9). NaN(not a number)
10). compile time error


No Dream Too Big
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Larry Olson wrote:
System.out.println(0.0 / (-4.0));


Good. But there is no trick in that, right? i.e. it is assumed everyone understands that! May be that is the reason Sahil didn't include that in the posted code



Hint: The answer is something that behaves slightly different from zero.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Before this topic fades to the next page....

Henry Wong wrote:
Larry Olson wrote:
System.out.println(0.0 / (-4.0));


Good. But there is no trick in that, right? i.e. it is assumed everyone understands that! May be that is the reason Sahil didn't include that in the posted code



Hint: The answer is something that behaves slightly different from zero.



The answer is negative zero. This value is slightly different from the normal zero...

http://en.wikipedia.org/wiki/Signed_zero

The sign is maintained, so if further math is done, such as it is used as the divisor to any positive dividend, the quotient is negative infinity.

Henry
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
It was really important !!!

Thanks Henry !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ID:6 SCJP Question of the day : Saturday June 12 2010