我的java exponentiation语法错了吗?

时间:2014-09-14 01:17:30

标签: java math

我正在尝试使用Heron公式计算三角形的面积,但我认为我在Math.pow函数中做错了,因为只要我添加它,我的打印语句不再有效,程序无法编译。这就是我所拥有的:

public class Challenge
{
    public static void main( String[] args )
    {
        double a;

        a = triangleArea(3, 3, 3);
        System.out.println("A triangle with sides 3,3,3 has an area of:" + a);

        a = triangleArea(3, 4, 5);
        System.out.println("A triangle with sides 3,4,5 has an area of:" + a);

        a = triangleArea(9, 9, 9);
        System.out.println("A triangle with sides 9,9,9 has an area of:" + a );
    }

    public static double triangleArea( int a, int b, int c )
    {
        double area;
        double s = (a+b+c)/2;
        s= (s*(s-a)*(s-b)*(s-c));
        area= Math.pow(double s,double b=.5) // this line has the error
        return area;
    }
}

编译器列出以下错误:

Challenge.java:22: error: '.class' expected
        area= Math.pow(double s,double b=.5) // this line has the error
                              ^
Challenge.java:22: error: ';' expected
        area= Math.pow(double s,double b=.5) // this line has the error
                               ^
Challenge.java:22: error: ';' expected
        area= Math.pow(double s,double b=.5) // this line has the error
                                           ^
3 errors

这些错误意味着什么?我该如何修理它们?

1 个答案:

答案 0 :(得分:1)

此,

area= Math.pow(double s,double b=.5)    

应该是这样的,

area = Math.pow(s,0.5);
return area;