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 < ...
随机推荐
- 天兔(Lepus)监控操作系统(OS)安装配置
监控和被监控端都要安装和配置snmp: [root@HE1bin]# yum install net-snmp* [root@HE1bin]# vi /etc/snmp/snmpd.conf 41行将 ...
- shell 命令合并文本
之前想把代码打印出来看来着,后来合并完之后放在word里发现有2000多页,然后放弃了~anyway,这个命令还是挺有用的. 比如我有文本a001.dat, a002.dat, a003.dat .. ...
- JS前端的分享功能
给网页加上分享代码,借助网友的力量推广网站,目前已经很流行了 以下是网页代码 QQ空间分享代码如下: <a href="javascript:void(0);" onclic ...
- 使AIX下ksh可以翻查上一条命令
http://blog.csdn.net/wangjialiang/article/details/7106393 http://www.blogjava.net/03081626/archive/2 ...
- Java 的String类
String类 1.String对象的初始化 由于String对象特别常用,所以在对String对象进行初始化时,Java提供了一种简化的特殊语法,格式如下: String s = “abc”; s ...
- PHP + Memcache 实现Session共享
一.安装Memcache和PHP扩展 Windows下的Memcache安装:1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached2. 在终端(也即cmd ...
- 《RDLC部署》RDLC部署到IIS缺少DLL程序集
1.错误:从vs生成网站部署到服务器后打开RDLC报表却提示缺少DLL程序集. 一般是缺少如下文件 1. Microsoft.ReportViewer.Common.dll 2. Microsof ...
- SSM框架注解整合
一.web应用环境 1.ServletContext 对于一个web应用,其部署在web容器(比如:tomcat)中,web容器提供其一个全局的上下文环境,这个上下文就是ServletContext, ...
- Array数组常用的5个方法
es6 时代来临了,不知道es5 你熟知了吗? 在此介绍一个我常用到的5个方法,万恶的ie9一下并不支持,需要做兼容慎用 indexOf indexOf()方法返回在该数组中第一个找到的元素位置,如果 ...
- 笔记之《用python写网络爬虫》
1 .3 背景调研 robots. txt Robots协议(也称为爬虫协议.机器人协议等)的全称是"网络爬虫排除标准"(Robots Exclusion Protocol),网站 ...