• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
https://coderanch.com/t/498524/java-programmer-SCJP/certification/ID-SCJP-day-Wednesday-June

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And don't forget...



Henry
 
Larry Olson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was really important !!!

Thanks Henry !!!
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic