一、junit、hamcrest和eclemma的安装。
1.junit和hamcrest在新建了junitHw1工程后在build path里通过add external jars添加junit-4.12.jar和hamcrest-all-1.3.jar。
2.eclemma在eclipse下点击help-eclipse marketplace-find-eclemma安装,重启eclipse。
二、编程判断三角形是等边三角形、等腰三角形或不等边三角形。
public class triangle { private static int error = 0; private static int equilateral = 1; private static int isosceles = 2; private static int scalene = 3; public static int triangletype(int a,int b, int c){ if(a <= 0 || b <= 0 || c <= 0){ return 0; }else if(a + b > c && a + c > b && b + c > a){ if ( a == b && b == c){ System.out.println("This is a equilateral triangle."); return 1; }else if (a == b || a == c || b == c){ System.out.println("This is a isosceles triangle."); return 2; }else { System.out.println("This is a scalene triangle."); return 3; } }else{ return 0; } } }
创建测试类
public class triangle { private static int error = 0; private static int equilateral = 1; private static int isosceles = 2; private static int scalene = 3; public static int triangletype(int a,int b, int c){ if(a <= 0 || b <= 0 || c <= 0){ return 0; }else if(a + b > c && a + c > b && b + c > a){ if ( a == b && b == c){ System.out.println("This is a equilateral triangle."); return 1; }else if (a == b || a == c || b == c){ System.out.println("This is a isosceles triangle."); return 2; }else { System.out.println("This is a scalene triangle."); return 3; } }else{ return 0; } } }
三、测试结果
原文:http://www.cnblogs.com/dpcn/p/5295477.html