How to convert a double to integer ?

Hi,how do convert an output of a pow(2,n) method of Math class to integer. Since this pow(x double, y bouble) gives an output of type double, how do i convert this output to integer if i want the value returned as an integer ?thanks aron
[265 byte] By [aron_phila] at [2007-11-27 9:36:07]
# 1
(int)
ejpa at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 2

By casting (but note that this may not yield the results you want)...

class Test {

public static void main(String[] argv) {

double a = 5.5;

double b = 6.6;

int c = (int)(a + b);

System.out.println(c);

}

}

Navy_Codera at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 3
int value = Integer.parseInt(String.valueOf(Math.pow(2,3)));I'm sure others can make it uglier.
floundera at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 4
Could you please elaborately explain your statement. I am basically trying to understand the concept. What does valueOf(double y)do and why String class and why pasrInt()... please explain elaborately if you could thats great !! thanx
aron_phila at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 5

> Could you please elaborately explain your statement.

> I am basically trying to understand the concept. What

> does valueOf(double y)do and why String class and why

> pasrInt()... please explain elaborately if you could

> thats great !! thanx

@flounder: Now look at what you've gone and done to this poor guy ...

Navy_Codera at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 6
My reply was meant as a joke. Don't do it this way. See reply #1.
floundera at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 7
so is the reply #1 correct or is the reply #3 more sophisticated ?Message was edited by: aron_phil
aron_phila at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 8
#1 is correct#5 is not sophisticated. It is convoluted as hell.oops ... I meant reply #3....Message was edited by: Navy_Coder
Navy_Codera at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 9
Reply #3 is not more sophisticated. In fact it is deliberately awful for humor purposes.
paulcwa at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 10

<stunned>

In other threads I have provided good advice of how to implement something and had it totally ignored. Here I deliberately provided bad advice and for some reason OP has zeroed in on it instead of the cleaner more sensible explanation. So now I know what I have to do in future in order to be "heard".

floundera at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 11
In all this hubbub, is it ok to mention the BigInteger pow method?
petes1234a at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 12

> So now I know what I have

> to do in future in order to be "heard".

The shorter the answer, the more likely it is to be ignored AFAICS. The long-winded answers with all the crappy code seem to get all the attention.

That doesn't stop me trying to post minimalist answers, though. It's just the way I am.

ejpa at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 13
I recall once a person asked if generics would be removed from JDK 1.6, and I said (sarcastically) that not only was that true, but also the letter "e" would be removed from the supported character sets. The OP of that thread believed me.
paulcwa at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...
# 14
int i = (int)Math.pow(x, y);
jverda at 2007-7-12 23:04:29 > top of Java-index,Java Essentials,New To Java...