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";
}//否则为不等边三角形 } }

Triangle Problems的更多相关文章

  1. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  2. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  3. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  4. [LeetCode]题解(python):120 Triangle

    题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to ...

  5. [LeetCode]题解(python):119 Pascal's Triangle II

    题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...

  6. [LeetCode]题解(python):118 Pascal's Triangle

    题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pa ...

  7. 【LeetCode OJ】Pascal's Triangle II

    Problem Link: http://oj.leetcode.com/problems/pascals-triangle-ii/ Let T[i][j] be the j-th element o ...

  8. 【LeetCode OJ】Pascal's Triangle

    Prolbem Link: http://oj.leetcode.com/problems/pascals-triangle/ Just a nest-for-loop... class Soluti ...

  9. 【LeetCode OJ】Triangle

    Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j < ...

随机推荐

  1. react中常用的一些方法

    React.createClass:创建一个ReactClass(组件类),参数是一个对象且必须带有 render 属性方法,该方法必须返回一个封闭的容器(容器内可以有其它不限结构的容器)或 null ...

  2. android 快捷技巧

    快捷方式 <!--[if !supportLists]-->0. Ctrl + 1 (快速修复) <!--[if !supportLists]-->1. Ctrl + D (删 ...

  3. Linux笔记(六) - 压缩解压命令

    (1)压缩文件( gz):gzip-d 解压只能压缩文件,不保留原文件例:gzip a.txt(2)解压文件( gz):gunzip 例:gunzip a.txt.gz(3)打包目录(tar):tar ...

  4. KB奇遇记(7):不靠谱的项目实施计划

    在ERP项目启动前期,项目组两方项目经理和我等几个人单独跟总裁开会,讨论了初步的ERP实施计划,本来第一期上线只是考虑上其中一家工厂而已,结果临时加入了深加工的工厂.本来项目组预定计划是2017年1月 ...

  5. ORACLE_INSERT

    Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) values(value1,value2,...)这种形式的在应用程序开发中必不可少.但我 ...

  6. GIS制图课程目录

    由于更新次序跳跃式更新,因此很有必要整理一下全书目录,并将会按照实际学习的顺序进行更新. [前言] GIS制图课程前言 [理论篇] 理论篇-地图学与GIS制图的基础理论(一) 理论篇-地图学与GIS制 ...

  7. button快速点击造成多次相应的解决办法

    UIButton+touch.h #import <UIKit/UIKit.h> #define defaultInterval 3 //默认时间间隔 @interface UIButto ...

  8. indexOf()--数组去重

    @(JavaScript) 数组去重方法有多中,这里列举出自己认为比较容易理解的方法. 思路: 创建一个新的空数组,用来存放去重后的新数组. 利用for循环循环遍历需要去重的数组. 利用indexOf ...

  9. PLSQL触发器

    触发器权限 数据库创建用户时想要在本用户下使用触发器,需要给用户触发器的权限 使用DBA用户执行  GRANT CREATE TRIGGER TO user_name; 如果想在当前用户下创建其他用户 ...

  10. API内部文件读取

    直接上代码吧 尝试将项目复制后建一个新的项目,结果总是有问题,不过可以把原项目转换为新项目,方法如下: 1.项目右键在android tools 有个 rename application packa ...