小编Duy*_*rần的帖子

返回方法重载

我是Java的新手,我自己也在学习.我尝试重载方法时遇到了麻烦.这是代码

 public static void main(String[] args) {
        calculateScore();
        calculateScore(500);
        calculateScore("Duy", 600);
        calcFeetAndInchesToCentimetres(100, 3.5);
        calcFeetAndInchesToCentimetres(100*12 + 3.5);
    }

 public static double calcFeetAndInchesToCentimetres(double feet, double inches) {
        if (feet >= 0 && inches >= 0 && inches <= 12) {
            double footToInches = feet * 12;
            double centimetres = (inches + footToInches) * 2.54;
            System.out.println("The value in centimetres is " + centimetres + " cm.");
            return centimetres;
        } else {
            return -1;
        }
    }

    public static double calcFeetAndInchesToCentimetres(double inches) {
        if (inches …
Run Code Online (Sandbox Code Playgroud)

java methods overloading return

3
推荐指数
1
解决办法
145
查看次数

标签 统计

java ×1

methods ×1

overloading ×1

return ×1