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

        }

}
时间: 2024-10-31 13:07:38

Triangle Problems的相关文章

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

LeetCode——Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom is 11 (i

[LeetCode][JavaScript]Pascal&#39;s Triangle

Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] https://leetcode.com/problems/pascals-triangle/ 杨辉三角. 每行第一个和最后一个是1,其余是pre[i - 1] +

[LeetCode][JavaScript]Triangle

Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to bottom

【leetcode】118. Pascal&#39;s Triangle

@requires_authorization @author johnsondu @create_time 2015.7.23 19:54 @url [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) /************************ * @description: simple. * @time_complexity: O(n) * @space_complexity: O(n) ****

Pascal&#39;s Triangle I,II

题目来自于Leetcode https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] class Solution { public: vector<vecto

【Leetcode】Pascal&#39;s Triangle II

题目链接:https://leetcode.com/problems/pascals-triangle-ii/ 题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 思路: 要求空间复杂度为O

Triangle 1.6 (A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator)

Triangle A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator. Version 1.6 Copyright 1993, 1995, 1997, 1998, 2002, 2005 Jonathan Richard Shewchuk 2360 Woolsey #H / Berkeley, California 94705-1927 Bugs/comments to [email protected] Creat

LeetCode——Pascal&amp;#39;s Triangle

Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 原题链接:https://oj.leetcode.com/problems/pascals-triangle/ 题目 :给定n,生成n行的帕斯卡三角形. 思路:帕斯卡三角形 也就是 杨辉三角形,依据