Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 )
 
Larry Olson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

And don't forget...



Henry
 
Larry Olson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was really important !!!

Thanks Henry !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic