Tuesday, July 28, 2009

Jcreator help and errors in the code??

public class Exercisethree


{


public static void main (String[]args)


{


int A =10;


int B = 15;


int C = 20;


if(A%26lt;B+C)


if(B%26lt;A+C)


if(C%26lt;A+B)


{int triangle = 1;}


if (triangle =1)


{


System.out.println("This cannot be a triangle");


}


else


{


double S = (A+B+C)/2;


double area = (SQRT(S*(S-A)*(S-B)*(S-C)));


System.out.println ("the area of this triangle is " + area);}





}


}





and the errors are the following:


-cannot find symbol variable triangle


-cannot find symbol method (SQRT)(double)





??

Jcreator help and errors in the code??
Hi,





You have three errors which need addressing.





1. The line that says {int triangle = 1;}





Change to {int triangle = 1; and move the closing }all the way down to the end of the else statement.





2. The if (triangle = 1) line cannot work because you have created a condition loop, and these loops can only take a true or false statement. In this case true is equivalent to triangle being equal to 1 so change that line to read:





if(true)





3. Change the line that reads double area = (SQRT(S*(S-A)*(S-B)*(S-C))); to:





double area = (Math.sqrt(S*(S-A)*(S-B)*(S-C)));





the square root function [sqrt] is a subclass of the main class Math, thus you need to type it as Math.sqrt





Hope this helps.

flower girl dresses

No comments:

Post a Comment