• 0

[JAVA] Square Root


Question

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

6 answers to this question

Recommended Posts

  • 0

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

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.