i am getting compilation error..
javac test.java
test.java:8: cannot assign a value to final variable MIN_VALUE
Integer.MIN_VALUE = 2147483648 ;
^
test.java:9: cannot assign a value to final variable MAX_VALUE
Integer.MAX_VALUE = 2147483647 ;
^
2 errors
how can i remove compilation error? what changes i have to do?
Shekar.
Thanks,
Shekar
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
Integer.MIN_VALUE already has this value assigned to it  defined by Java. You should be able to just remove those two lines entirely, and it should be fine.
yes .... t removed those lines and it worked.
my output:
Round f4 is 2147483648
Round f5 is 2147483647
Round f7 is 2147483648
why Round f7 is 2147483648 ?? given float f7 = 2147483655f, so the answer should be 2147483655 like others (bcoz nothing to round off...its whole number).
but why the last output is 2147483648 ?
If you look at the method signatures for Math.round(), the one that accepts
a float as an argument returns an int value (the nearest int), hence 2147483648
hi, its not clear to me , how you are calculating this output ?
float f7 = 2147483655f;
see , the last two digit of f7 ..its 55..ok.The output i have got having last two digit 48....clearly these are not nearest integer. so, i think your explanation is not correct.
one more thing to note,float f7 = 2147483655f; ....it has no decimal point at all...so how can i think of rounding off?
anyway, i am not clear about the third output...will you be explicit more?
can you tell me how are you calculating the third output in a simple way.
thanks
If you want more accuracy you need to work in doubles and longs.
The nice thing about Standards is that there are so many to choose from!
so your number's magnitude is at best accurate to about 7 digits.
do you mean the output i am getting is a kind of garbage ?
if it is not a garbage then can you tell me the mathematics , how i am getting that?
i simply want to know the math...can you show me how that calculation is going on to produce that output?
is it too difficult?
hi, its not clear to me , how you are calculating this output ?
float f7 = 2147483655f;
see , the last two digit of f7 ..its 55..ok.The output i have got having last two digit 48....clearly these are not nearest integer. so, i think your explanation is not correct.
My explanation is correct, perhaps not complete.
Here are the relevant parts from the API (from the Math class)
static long round(double a)
Returns the closest long to the argument.
static int round(float a)
Returns the closest int to the argument.
The difference is the method that accepts a double returns a long, so, the
number ending in 55 fits into a long, whereas it doesn't fit into an int
when the same number is 'typed' as a float.
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
