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 < ...
随机推荐
- js原生继承之——构造函数式继承实例
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- catalan卡特兰数
卡塔兰数是组合数学中一个常在各种计数问题中出现的数列.以比利时的数学家欧仁·查理·卡塔兰(1814–1894)命名.历史上,清代数学家明安图(1692年-1763年)在其<割圜密率捷法>最 ...
- ZOJ-2343-Robbers
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1398 题意: 输入t 有t个测试用例每个测试用例第一行输入三个数n, ...
- 第一个Servlet程序及分析
第一个Servlet程序: package cc.openhome; import java.io.IOException; import java.io.PrintWriter; import ja ...
- Number,parseInt,parseFloat函数
Number,parseInt,parseFloat函数 console.group('Number'); console.log(Number( console.log(Number( consol ...
- Flex Socket 安全沙箱问题解决
Flex使用Socket与C++通讯时遇到了安全沙箱问题,NND,折腾我半天,这是我的解决方法: 1):策略文件与主套接字在同一端口,只需调用 Socket.connect() 或 XMLSocket ...
- 动态加载css方法实现和深入解析
一.方法引用来源和应用 此动态加载css方法 loadCss,剥离自Sea.js,并做了进一步的优化(优化代码后续会进行分析). 因为公司项目需要用到懒加载来提高网站加载速度,所以将非首屏渲染必需 ...
- HDU5875
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- ADXL345经验总结,采用SPI和I2C总线操作
一. ADXL345简介 ADXL345是ADI公司推出的三轴(x,y,z)iMEMS数字加速度计(digital accelerometer),具有在16G下高分辨率(13Bit)测量能 ...
- json基础教程|理解Json
一. 在异步应用程序中发送和接收信息时,可以选择以纯文本和 XML 作为数据格式.这一期讨论一种有用的数据格式 JavaScript Object Notation(JSON),以及如何使用它更轻松地 ...