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.

  1. package testTriangle;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import java.util.Arrays;
  6. import java.util.Collection;
  7.  
  8. import org.junit.Test;
  9. import org.junit.runner.RunWith;
  10. import org.junit.runners.Parameterized;
  11. import org.junit.runners.Parameterized.Parameters;
  12.  
  13. import triangle.triangle;
  14.  
  15. @RunWith(Parameterized.class)
  16. public class testTriangle {
  17.  
  18. private int a;
  19. private int b;
  20. private int c;
  21. private String expected;
  22. public testTriangle(int a,int b, int c, String expected){
  23. this.a = a;
  24. this.b = b;
  25. this.c = c;
  26. this.expected= expected;
  27.  
  28. }
  29.  
  30. @Parameters
  31. public static Collection<Object[]> getData(){
  32. return Arrays.asList(new Object[][]{
  33. {3,3,3,"equilateral"},
  34. {1,2,3,"scalene"},
  35. {5,5,7,"isosceles"},
  36. {4,6,6,"isosceles"}
  37. });
  38. }
  39.  
  40. @Test
  41. public void test() {
  42. assertEquals(this.expected,triangle.triangleshape(a,b,c));
  43. }
  44.  
  45. }

  

  1. package triangle;
  2.  
  3. public class triangle {
  4.  
  5. public static String triangleshape(int a,int b, int c){
  6. if( (a + b) < c||(a - b) > c){
  7. return "error";
  8. }//判断是否符合三角形三条边的情况,即两边之和大于第三边,两边之差小于第三边;
  9. if(a == b && a == c && b == c){
  10. return "equilateral";
  11. }//三条边相等即为等边三角形
  12. else if(a == b || a == c || b == c){
  13. return "isosceles";
  14. }//任意两边相等即为等腰三角形,并且等边三角形也是等腰三角形
  15. else{
  16. return "scalene";
  17. }//否则为不等边三角形
  18.  
  19. }
  20.  
  21. }

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. Flash中图片的逐步加载

    在Flash中,有Loader类,可以从外部载入一张图片(或swf文件).但是有个不好的地方就是,不像浏览器那样一边下载一边显示.所幸的是,Flash提供了Loader.loadBytes方法和URL ...

  2. 使用AIR进行移动APP开发常见功能和问题(上)

    1.  获取最近联系人 思路:侦听Geolocation的update事件,获取经度和纬度信息,再把坐标信息上传至服务器,服务器比较坐标信息算出距离,返回最近位置的若干个人. update时间在2种情 ...

  3. 用ant打包可运行的jar文件 (将第三方jar包放进你自己的jar包)

    http://blog.csdn.net/caiqcong/article/details/7618582 <span style="font-family:SimSun;font-s ...

  4. jQuery Deferred和Promise的使用介绍:

    deferred对象是从jquery1.5.0引入的一个新对象,ES6也引入了Promise的正式规范. 抽象来说,deferreds 可以理解为表示需要长时间才能完成的耗时操作的一种方式,相比于阻塞 ...

  5. EntityFramework Core 1.1有哪些新特性呢?我们需要知道

    前言 在项目中用到EntityFramework Core都是现学现用,及时发现问题及时测试,私下利用休闲时间也会去学习其他未曾遇到过或者用过的特性,本节我们来讲讲在EntityFramework C ...

  6. HDU5692(线段树+dfs序)

    Snacks Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  7. 蓝桥网试题 java 入门训练 A+B问题

    ---------------------------------------------------------------------------------------------------- ...

  8. [JS][jQuery]清空元素html("")、innerHTML="" 与 empty()的区别 、remove()区别

    清空元素html("").innerHTML="" 与 empty()的区别 一.清空元素的区别     1.错误做法一:           $(" ...

  9. C语言 一维数组叠加为二维数组样例

    这里参看memcpy的用法,将一个一维整型数组不停的叠加为二维数组 使用宏定义来控制二维数组的行列 代码如下: #include <stdio.h> #include <stdlib ...

  10. C语言一维数组复制

    /* * 通过自定义的函数memcpy实现复制功能,优点是不需要引用库函数 * 在windows平台下,通过sizeof测试发现: int 4字节 float 4字节 double 8字节 */ #i ...