0
  1. Write a method of type double called triangleArea which takes in two parameters of type double for the base and height of a triangle and returns the area.

Here is my code. On line "triangleArea(height,base);" an error message displays: **cannot find symbol symbol: variable height location: class HWA

cannot find symbol symbol: variable base location: class HWA Assign Return Value to New Variable

public class HWA {

public static void main(String[] args{  
    triangleArea(height,base);    
} 

public static double triangleArea(double height, double base){
 height = 12;
 base = 6;  
 double equal = (1/2)*(height*base);     
 return equal;    
     }  
}

What am I doing wrong or how can I fix it and still follow the requirements listed above?

yes11i
  • 33
  • 3
  • 2
    Well, the variables `height` and `base` are not defined in your `main()` function. In addition, your `main()` function definition is missing a closing parenthesis. – Jerrybibo Apr 26 '17 at 00:10
  • suppose you code should be modified like below. public class HWA { `public static void main(String[] args){ triangleArea(12,6); } public static double triangleArea(double height, double base){ double equal = (1/2)*(height*base); return equal; } }` – Rajith Pemabandu Apr 26 '17 at 00:16
  • Yes, you need to add the closing parens on main, then you need to move height = 12 and base = 6 to the main method before the call to triangleArea. You'll need to change it to `double height = 12;` and `double base = 6;` when you do that. Also, you aren't doing anything with the return value of triangleArea. You need to assign it like `double area = triangleArea(height, base); Then I don't know print it. This code wont' do anything right now – Novaterata Apr 26 '17 at 00:16

0 Answers0