This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

it's clearly mentioned in jaworaski (chap 3)that an integer by zero an ArithmeticException. positive floating-point value by zero POSITIVE_INFINITY. negative floating point value by zero NEGATIVE_INFINITY. Note that when the sign of zero is negative, such as -0, the sign of the result is reversed.

so i write a small program but it is not behaving expectedly class DivisionTest { public static void main(String m[]) { int i =10; float j = 10.0f; System.out.println(j/0); System.out.println(-j/0); System.out.println(-j/(-0)); } } according to my understanding the o/p should be infinity -infinity infinity but the out put is DivisionTest.java:7: Arithmetic exception. System.out.println(j/0); ^ DivisionTest.java:8: Arithmetic exception. System.out.println(-j/0); ^ DivisionTest.java:9: Arithmetic exception. System.out.println(-j/(-0)); ^ 3 errors

can anybody pls. throw some light why this is happening? i'm using WinNT /jdk1.2.1 thanx in advance deekasha

Hmmm.. that's interesting. I am running JDK 1.2.2 and it prints correct results for me ie., Infinity -Infinity -Infinity May be you can run a quick search on Sun's bug parade to see if this inconsistency was reported in JDK 1.2.1 and fixed later. Ajith

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).

Hi I think its got something to do with the java compiler,if i use JDK 1.2.2 then it compiles fine,but if i use JDK1.1.6 then it gives the compile time errors.I think the same is the problem with JDK1.2.1.Thanks. Surya [This message has been edited by Surya B (edited July 31, 2000).]

Hi,there: ---------------------------------------------- an integer by zero an ArithmeticException. positive floating-point value by zero POSITIVE_INFINITY. negative floating point value by zero NEGATIVE_INFINITY. Note that when the sign of zero is negative, such as -0, the sign of the result is reversed. so i write a small program but it is not behaving expectedly class DivisionTest { public static void main(String m[]) { int i =10; float j = 10.0f; System.out.println(j/0); System.out.println(-j/0); System.out.println(-j/(-0)); } } ----------------------------------------- I tried my 1.2.2 compiler, the result is same as above, but when you say" if sign of zero is negative, the sign of result is reserve??? The last two statements print all the same " -Infinity", why? please advise. Thanks

Hi, I am using JDK 1.2 & WIN NT and it prints correct results for me ie., Infinity -Infinity -Infinity Thanks [This message has been edited by Netla Reddy (edited July 31, 2000).]

To answer Helen's qn: The primitive integer types do not differentiate between +0 and -0. So when the integral operand is promoted to a floating-point type, it simply becomes 0.0. 10.0/0 will give Infinity 10.0/-0 will also give Infinity But the floating-point types differentiate between +0.0 and -0.0. 10.0/0.0 will give Infinity 10.0/-0.0 will give -Infinity