PDA

Click to See Complete Forum and Search --> : resolved - Vb to java any help appreciated ... (1 line)


illskills
May 22nd, 2010, 08:42 PM
can someone help me convert this 1 line of vb code to java ...

the line below calculates the volume of a bowl in vb (and works)

Dim dvolume As Double = Math.PI * dRadius * dHeight ^ 2 - (Math.PI * dHeight ^ 3) / 3

....

i have tried to add it to my java android project and am not getting the same result ....

using

Double dvolume = Math.pow(Math.PI * dRadius * dHeight, 2) - (Math.pow(Math.PI * dHeight, 3) / 3;

when i use the values 1.5 for the radius and 1 for the height in my vb app i get the result 3.67 m3

when i try the same in java with the above example im getting either 12 or -3 which isnt correct can anyone help pls

Zach_VB6
May 22nd, 2010, 08:52 PM
You are reading your VB code differently than the IDE. The IDE reads it like this:(Math.PI * dRadius) * (dHeight ^ 2) - (Math.PI * (dHeight ^ 3)) / 3Java code:Double dvolume = Math.PI * dRadius * Math.pow(dHeight, 2) - ((Math.PI * Math.pow(dHeight, 3)) / 3);

illskills
May 22nd, 2010, 09:00 PM
thanks dude im going to try this out now :)

... im new to java (its like learning to walk again lol)

illskills
May 22nd, 2010, 09:04 PM
worked like a dream thanks again dude :)