Sam executes the following program segment and the answer displayed is zero
irrespective of any non zero values are given. Name the error. How the program
can be modified to get the correct answer?
void triangle(double b, double h)
{
double a;
a = ½ * b * h;
System.out.println(“Area=”+a);
}
Solution
logical error
void triangle(double b, double h)
{
double a;
a = 0.5 * b * h;
System.out.println(“Area=”+a);
}