Re: Strange java behaviour
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Thu, 28 Sep 2006 14:03:40 GMT
priyom wrote:
Please got through the following code snippet.
class NanTest {
public static void main ( String args [ ] ) {
int intX = 10 ; // line 1
float floatX = 10 ; // line 2
double doubleX = floatX / 0 ; // line 3
double doubleY = intX / 0 ; // line 4
System . out . println ( doubleX == doubleY ) ; // line 5
}
}
It throws exception on line 4 but not on line 3.
Could anyone please explain this.
Line 4 is an int division by zero, and there is no way to represent the
result as an int, so it throws an exception.
Line 3 is a float division by zero, and there is a value,
Float.POSITIVE_INFINITY, that represents the result of dividing a
positive float by a zero float.
Patricia
.
- References:
- Strange java behaviour
- From: priyom
- Strange java behaviour
- Prev by Date: Re: want to read all elements of xml using jdom ?
- Next by Date: Re: Permutations
- Previous by thread: Re: Strange java behaviour
- Next by thread: Java XviD player
- Index(es):
Relevant Pages
|
|