| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 855 人关注过本帖
标题:新手求解释 这是什么意思
只看楼主 加入收藏
dyfogy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-18
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:8 
新手求解释 这是什么意思
/**
     * Get the length of a side
     *
     * @param side the side number (0-2)
     * @return the side's length, or -1 if an invalid side was supplied as a
     *         parameter
     */
    public int getSide(int side) {
        // check the side number is in the valid range
        if (side >= 0 && side < 3) {
            return sides[side];
        } else {
            // invalid side number given, return -1
            return -1;
        }
    }
搜索更多相关主题的帖子: supplied invalid public number return 
2014-02-18 21:51
dyfogy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-18
收藏
得分:0 
谁给说明下这段程序是什么意思 谢谢
2014-02-18 21:54
husiwen
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:227
专家分:1125
注 册:2010-5-23
收藏
得分:5 
这一点代码是很简单,具体想知道什么意思,你要把整个类代码贴出来
不能这样断章取义,让别人帮你猜?
2014-02-19 09:18
dyfogy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-18
收藏
得分:0 
public class Triangle {
    private int[] sides;

    /**
     * Constructs a triangle given three side lengths
     *
     * @param firstSide the first side
     * @param secondSide the second side
     * @param thirdSide the third side
     */
    public Triangle(int firstSide, int secondSide, int thirdSide) {
        // put the parameters into an private array internal to the object
        sides = new int[3];
        sides[0] = firstSide;
        sides[1] = secondSide;
        sides[2] = thirdSide;

        // The rest of the code in the constructor sort the sides of the
        // triangle
        // in the sides array into length order. This makes the invalid triangle
        // test easy
        // to perform in the getType() method

        int temp; // used to temporarily store a side length when doing a length
                    // swap

        if (sides[0] > sides[1]) {
            // swap sides at array indexes 0 and 1
            temp = sides[0];
            sides[0] = sides[1];
            sides[1] = temp;
        }

        if (sides[1] > sides[2]) {
            // swap sides at array indexes 1 and 2
            temp = sides[1];
            sides[1] = sides[2];
            sides[2] = temp;
        }
    }

    /**
     * Get the length of a side
     *
     * @param side the side number (0-2)
     * @return the side's length, or -1 if an invalid side was supplied as a
     *         parameter
     */
    public int getSide(int side) {
        // check the side number is in the valid range
        if (side >= 0 && side < 3) {
            return sides[side];
        } else {
            // invalid side number given, return -1
            return -1;
        }
    }

    /**
     * Returns a message indicating the type of the triange i.e. "equilateral",
     * "isosceles", "scalene" or "invalid".
     */
    public String getType() {

        // test whether the sides are of valid lengths
        if (sides[0] <= 0 || sides[1] <= 0 || sides[2] <= 0) {
            return "invalid";
        }

        // test for an invalid triangle
        if (sides[0] + sides[1] < sides[2]) {
            return "invalid";
        }

        // if two sides are equal, the triangle type is isosceles
        if (sides[0] == sides[1] || sides[1] == sides[2]
                || sides[2] == sides[0]) {
            return "isosceles";
        }

        // if all three sides are of equal length, it's an equilateral triangle
        if (sides[0] == sides[1] && sides[1] == sides[2]) {
            return "equilateral";
        }

        // none of the above, therefore it's a scalene triangle
        return "scalene";
    }
}
这个代码是让建立junit 然后改错的早先的那段代码不太会建立junit的程序进行检测,麻烦大神讲解
2014-02-19 09:43
dyfogy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-18
收藏
得分:0 
回复 3楼 husiwen
大师能帮忙解决问题吗
2014-02-19 20:24
tj06051102
Rank: 2
等 级:论坛游民
帖 子:9
专家分:40
注 册:2014-2-20
收藏
得分:5 
如果side大于等于0并且小于3
返回数组下标为side的值
否则返回-1
2014-02-20 22:52
dyfogy
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-2-18
收藏
得分:0 
回复 6楼 tj06051102
那这段的junit应该如何书写,请大师指教
2014-02-21 09:21
java小蚂蚁
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:上海
等 级:贵宾
威 望:18
帖 子:558
专家分:2186
注 册:2013-7-2
收藏
得分:5 
public int getSide(int side) {
        // check the side number is in the valid range
        if (side >= 0 && side < 3) {
            return sides[side];
        } else {
            // invalid side number given, return -1
            return -1;
        }
    }
只看这段,这是一个int类型的方法,其他地方调用由于方法属性为public ,所以可能是外面的类调用,调用类似***.getSide(***);括号里面传入一个int类型的参数,然后进入当前方法,判断传入参数值大小,话说,这个都看不懂,还是不要看了,先去学学java基础。

学海无涯#¥%……&*(
2014-02-21 10:01
tj06051102
Rank: 2
等 级:论坛游民
帖 子:9
专家分:40
注 册:2014-2-20
收藏
得分:5 
测试?
大概就这么写
  public static void main(String[] args) {
    Triangle triangle = new Triangle(1,2,3);
    System.out.println(triangle.getSide(1));
  }
2014-02-21 17:04
快速回复:新手求解释 这是什么意思
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019272 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved