Triangle Problems
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的更多相关文章
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- [LeetCode]题解(python):120 Triangle
题目来源 https://leetcode.com/problems/triangle/ Given a triangle, find the minimum path sum from top to ...
- [LeetCode]题解(python):119 Pascal's Triangle II
题目来源 https://leetcode.com/problems/pascals-triangle-ii/ Given an index k, return the kth row of the ...
- [LeetCode]题解(python):118 Pascal's Triangle
题目来源 https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pa ...
- 【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 ...
- 【LeetCode OJ】Pascal's Triangle
Prolbem Link: http://oj.leetcode.com/problems/pascals-triangle/ Just a nest-for-loop... class Soluti ...
- 【LeetCode OJ】Triangle
Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j < ...
随机推荐
- Chrome 报 Resource interpreted as Script but transferred with MIME type text/plain 警告的解决办法
http://www.2cto.com/os/201312/262437.html 安装了VS2012之后,chrome在加载页面的时候会报 Resource interpreted as Scrip ...
- 持续集成的一些讨论(CI)
如何保证程序开发的新功能降低BUG,那就是需要他们自己写用测试工具来写测试用例,包括Mocha(JS).Junit(Java).GTest(C++):而上传到SVN或者GIT后,又如何保证能跟原有的功 ...
- LinuxMint18配置Grub2默认启动操作系统
---恢复内容开始--- 之前电脑里面装了太多系统太乱了,刚好假期回家有一些空闲时间于是开始了重装计划. 现在重新弄好了,有两个系统,一个是Windows10,另一个是LinuxMint18,但是我平 ...
- 关于Visual Studio未能加载各种Package包的解决
参考微软社区的一个答复解决了VS2013的问题: 进入VS对应的用户缓存文件夹,删掉那个Microsoft.VisualStudio.Default.cache缓存文件,就可以了. 这个错误估计是我们 ...
- 在C语言中以编程的方式获取函数名
仅仅为了获取函数名,就在函数体中嵌入硬编码的字符串,这种方法单调乏味还易导致错误,不如看一下怎样使用新的C99特性,在程序运行时获取函数名吧. 对象反射库.调试工具及代码分析器,经常会需要在运行时访问 ...
- javascript运行机制详解: 再谈Event Loop(转)
作者: 阮一峰 日期: 2014年10月 8日 一年前,我写了一篇<什么是 Event Loop?>,谈了我对Event Loop的理解. 上个月,我偶然看到了Philip Roberts ...
- matlab for循环应用(阶乘及the day of year)
一.N的阶乘 %脚本文件:test.m %N的阶乘 使用举例 % 定义变量 % ii ---循环变量,也就是循环次数 % N ---N的阶乘 % N_factorial --计算N的阶乘 clc;cl ...
- Yarn init 命令在 Git Bash 中打开时的错误
最近一直在学习一些新的知识,ES5.ES6.Vue等,当然,作为程序,英文的阅读和听写能力也是要去学习的. 最近慕课网上的qbaty大神出了两套视频,分别是webpack和yarn,本着不断学习的精神 ...
- 内存管理 (C++)
转:http://hi.baidu.com/%D0%A1%B0%FC%D7%D349/blog/item/de1a8e4fa5eeafc3d0c86a68.html1.进程地址空间 Window ...
- C# 基础控制台程序的创建,输出,输入,定义变量,变量赋值,值覆盖,值拼接,值打印
基础学习内容有 Console.WriteLine("要输出的内容");//往外输出内容的 Console.ReadLine(); //等待用户输入,按回车键结束,防止程序闪退 控 ...