Alladaskill17 Posted March 11, 2009 Share Posted March 11, 2009 I need help with how to code for a square root.. Suppose to be "Area = Square root of S(S - Length1)(S - Length2)(S - Length3)" I have: if (Area = Math.sqrt(S(S - Length1)(S - Length2)(S - Length3))); Not working as I get multiple errors. ----jGRASP exec: javac -g C:\Documents and Settings\Administrator\My Documents\JAVA\MyTriangle.java MyTriangle.java:42: ')' expected if (Area = Math.sqrt(S(S - Length1)(S - Length2)(S - Length3))); ^ MyTriangle.java:42: not a statement if (Area = Math.sqrt(S(S - Length1)(S - Length2)(S - Length3))); ^ MyTriangle.java:42: ';' expected if (Area = Math.sqrt(S(S - Length1)(S - Length2)(S - Length3))); ^ MyTriangle.java:42: not a statement if (Area = Math.sqrt(S(S - Length1)(S - Length2)(S - Length3))); ^ MyTriangle.java:42: ';' expected if (Area = Math.sqrt(S(S - Length1)(S - Length2)(S - Length3))); ^ 5 errors Link to comment Share on other sites More sharing options...
0 [jon] Posted March 11, 2009 Share Posted March 11, 2009 Put a * between the terms... I.e.: if (Area = Math.sqrt(S*(S - Length1)*(S - Length2)*(S - Length3))); Link to comment Share on other sites More sharing options...
0 Alladaskill17 Posted March 11, 2009 Author Share Posted March 11, 2009 Thanks, reduced the errors, but when I did if (Area = Math.sqrt(S*(S - Length1)*(S - Length2)*(S - Length3))); I receive the following errors: MyTriangle.java:42: possible loss of precision found : double required: int if (Area = Math.sqrt(S*(S - Length1)*(S - Length2)*(S - Length3))); ^ MyTriangle.java:42: incompatible types found : int required: boolean if (Area = Math.sqrt(S*(S - Length1)*(S - Length2)*(S - Length3))); ^ 2 errors Link to comment Share on other sites More sharing options...
0 Alladaskill17 Posted March 11, 2009 Author Share Posted March 11, 2009 Tried: double Area = (Math.sqrt(S*(S - Length1)*(S - Length2)*(S - Length3)))); Which returned only one error: MyTriangle.java:39: ';' expected double Area = (Math.sqrt(S*(S - Length1)*(S - Length2)*(S - Length3)))); ^ 1 error Where is my error? Link to comment Share on other sites More sharing options...
0 Alladaskill17 Posted March 11, 2009 Author Share Posted March 11, 2009 Apparently it has to end in: ))));; It compiles, but why two ";" ? Link to comment Share on other sites More sharing options...
0 +M2Ys4U Subscriber¹ Posted March 11, 2009 Subscriber¹ Share Posted March 11, 2009 use == to test equality. Link to comment Share on other sites More sharing options...
0 JusT4SKy Posted March 12, 2009 Share Posted March 12, 2009 if (Area = (double) Math.sqrt(S*(S - Length1)*(S - Length2)*(S - Length3))); Add in the casting. I hope it may help you. Link to comment Share on other sites More sharing options...
Question
Alladaskill17
I need help with how to code for a square root..
Suppose to be "Area = Square root of S(S - Length1)(S - Length2)(S - Length3)"
I have:
Not working as I get multiple errors.
Link to comment
Share on other sites
6 answers to this question
Recommended Posts