0
I have to write a method called CalcTriangleArea
It takes two decimals as parameters (double) for the triangel base and height. The me th of should calculate the figure area and return resultat as a double My code in java public double calcTriangleAre(double base,double height){ result= double area; area = (double)base*height /2 Return result; } Error: row 3 double area class expected
3 ответов
+ 5
Your method is already receiving two numbers with "double" type. no need to use typecasting here.
To make it simple, you don't even need to declare any local variables, because the calculation is very short. Just return the value of the expression like this.
public double calcTriangleAre(double base, double height) {
return base * height / 2;
}
If you need to temporaryly store some parts of a calculation, review how a variable is declared, first specify the type, then the name, then you can assign the value with = operator.
Then your function can return this variable.
double area = base * height / 2;
return area;
+ 2
Java is statically typed so it requires data type. Row 3 is not a valid syntax. On row 4, you should specify data type for area.
Replace Return with return (keyword, case sensitive)
Tip: You can delete "result= " from line 3 and simply return area instead of result.
0
Thank you your code was right tibor thanks