class MathFun
{
private double far = ((double)5/9); // (5/9)
private double cel = ((double)9/5); // (9/5)
private double PI = Math.PI(); // (pi)
private double vol = ((double)4/3); // (4/3)
public MathFun ( ) { }
double fToC (double F)
{
double celsius = 5 * (F - 32) / 9;
return celsius;
}
double cToF (double C)
{
double fahrenheit = 9 * (C + 32) / 5;
return fahrenheit;
}
double calcSphere (double r)
{
double vol = 4/3;
double PI = Math.PI;
double sqr = Math.pow(r,3);
double volume = vol * PI * sqr;
return volume;
}
its saying that PI is not a variable, how do i change it in order to work.Why is the java class not compiling?
Whenever you want to use the pi value simply write Math.PI:
class MathFun
{
聽聽private double far = ((double)5/9); // (5/9)
聽聽private double cel = ((double)9/5); // (9/5)
聽聽private double vol = ((double)4/3); // (4/3)
聽聽public MathFun ( ) { }
聽聽double fToC (double F)
聽聽{
聽聽聽聽double celsius = 5 * (F - 32) / 9;
聽聽聽聽return celsius;
聽聽}
聽聽double cToF (double C)
聽聽{
聽聽聽聽double fahrenheit = 9 * (C + 32) / 5;
聽聽聽聽return fahrenheit;
聽聽}
聽聽double calcSphere (double r)
聽聽{
聽聽聽聽double vol = 4/3;
聽聽聽聽double sqr = Math.pow(r,3);
聽聽聽聽double volume = vol * Math.PI * sqr;
聽聽聽聽return volume;
聽聽}
}
RegardsWhy is the java class not compiling?
YAY! You've got:
Math.Pi() -- As a function in Line 5
Math.PI -- As a value in Line 24
Check the Java doc. One of those should not be right.
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment