Implementation Types of Triangle with Java and JUnit? -
i made typeoftriangle.java
public class typeoftriangle { public static int triangle(int a, int b, int c) { if (a<b && b<c && (a*a)+(b*b)>(c*c)) { system.out.println("triangular taper"); } else if(a<b && b<c && (a*a)+(b*b)=(c*c)) { system.out.println("right triangle"); } else if (a<b && b<c && (a*a)+(b*b)<(c*c)) { system.out.println("blunt triangle");} } }
and made class test typeoftriangletest.java
import junit.framework.*; public class typeoftriangletest extends testcase { public typeoftriangletest(string name) { super(name); } public void testsimple() { assertequals("triangular taper", typeoftriangle.triangle(6,8,10)); } }
but when run class test, there's 1 error. said
java:6: operator && cannot applied boolean,int } else if(a<b && b<c && (a*a)+(b*b)=(c*c)) {
so i'm supposed do? hmm , i'm confused return statement in typeoftriangle.java, because wanna return result of system.out.println, how make works?
you can correct modifying follows:
else if(a<b && b<c && ((a*a)+(b*b)==(c*c)))
to return something, change type string:
public class typeoftriangle { public static string triangle(int a, int b, int c) { if (a<b && b<c && (a*a)+(b*b)>(c*c)) { return "triangular taper"; } else if(a<b && b<c && ((a*a)+(b*b)==(c*c))) { return "right triangle"; } else if (a<b && b<c && (a*a)+(b*b)<(c*c)) { return "blunt triangle"; } return "not triangle"; } }
Comments
Post a Comment