BlockchainDeveloper
BlockchainDeveloper

Reputation: 520

Is my syntax for java exponentiation wrong?

I am trying to calculate the area of a triangle using Heron's formula, but I think I'm doing something wrong in the Math.pow function because as soon as I add it, my print statements no longer work and the program fails to compile. This is what I have:

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;
    }
}

The compiler lists the following errors:

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

What do these errors mean? How do I fix them?

Upvotes: 0

Views: 115

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201537

This,

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

should be something like,

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

Upvotes: 1

Related Questions