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

Sahil Kapoor

Ranch Hand

Posts: 316

posted 5 years ago

- 0

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

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 ....)

posted 5 years ago

- 0

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 )

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

Posts: 142

posted 5 years ago

- 0

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!

- 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!

Larry Olson

Ranch Hand

Posts: 142

Abhinav Yadav

Ranch Hand

Posts: 34

posted 5 years ago

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

- 0

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

posted 5 years ago

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

- 0

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.

posted 5 years ago

- 0

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

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

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

I agree. Here's the link: http://aspose.com/file-tools |