Triangle Problem

songxiuhuan 宋修寰

Import the Junit and eclemma

Choose the project and right click, choose the build path and choose the Junit and hamcrest.

Install eclemma

Help——install newsoftware——input the URL of the eclemma in my PC

Coding the triangle and testTriangle, to verify if it’s a triangle and equilateral, isosceles, or scalene.

When a==b==c it’s a equilateral one.

When a==b!=c it’s a isosceles one.

Others they are scalene.

KEY: A regular triangle must obey that a+b>c and a-b<c. Or there will be a failure.

package testTriangle;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collection; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters; import triangle.triangle; @RunWith(Parameterized.class)
public class testTriangle { private int a;
private int b;
private int c;
private String expected;
public testTriangle(int a,int b, int c, String expected){
this.a = a;
this.b = b;
this.c = c;
this.expected= expected; } @Parameters
public static Collection<Object[]> getData(){
return Arrays.asList(new Object[][]{
{3,3,3,"equilateral"},
{1,2,3,"scalene"},
{5,5,7,"isosceles"},
{4,6,6,"isosceles"}
});
} @Test
public void test() {
assertEquals(this.expected,triangle.triangleshape(a,b,c));
} }

  

package triangle;

public class triangle {

    public static String triangleshape(int a,int b, int c){
if( (a + b) < c||(a - b) > c){
return "error";
}//判断是否符合三角形三条边的情况,即两边之和大于第三边,两边之差小于第三边;
if(a == b && a == c && b == c){
return "equilateral";
}//三条边相等即为等边三角形
else if(a == b || a == c || b == c){
return "isosceles";
}//任意两边相等即为等腰三角形,并且等边三角形也是等腰三角形
else{
return "scalene";
}//否则为不等边三角形 } }

最新文章

  1. CSS教程:vlink,alink,link和a:link
  2. asp.net还原备份数据库(C#)
  3. lamp 网站打不开,不显示也不报错,
  4. 【TYVJ】1982 武器分配(费用流)
  5. 在汇编代码中调用C函数
  6. Cocos2d-JS中的cc.LabelAtlas
  7. iOS 9 之后更改状态栏字体颜色
  8. boost::thread 线程锁
  9. ETL几种方案对比
  10. 反汇编看c++引用
  11. JS - 数据类型的值拷贝函数(深拷贝)
  12. HDU2243 考研路茫茫――单词情结
  13. LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
  14. 前端/C# 前后台交互文件上传、下载
  15. (一) Getting Started
  16. webpack安装与配置初学者踩坑篇
  17. THML文档布局元素
  18. C#解析数组形式的json数据
  19. IP分类
  20. Spring框架管理开源的连接池

热门文章

  1. InnoDB的表类型,逻辑存储结构,物理存储结构
  2. 使用滚动条(ActionBar)
  3. Carthage - 一个简单、去集中化的Cocoa依赖管理器
  4. [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds...
  5. jQuery css,position,offset,scrollTop,scrollLeft用法
  6. doubango(4)--SIP协议栈传输层的启动
  7. HTTP服务器的本质:tinyhttpd源码分析及拓展
  8. arcpy.mapping常用四大件-Layer
  9. 史上最牛逼的文件bom头清除代码,万能检测清除php,js等等
  10. The type or namespace name &#39;****&#39; could not be found