繁体   English   中英

如何解决 main 类型中的方法 add(double, double, int, double) 不适用于参数 (double, double, double, double)

[英]how to solve The method add(double, double, int, double) in the type main is not applicable for the arguments (double, double, double, double)

如果您正在回复,请给我看代码和提示代码来自兄弟代码,我仍然在学习抱歉

我已经修复了其他几个错误,但它仍然不起作用

public class main {
    public static void main(String[] args) {
        double x = add(1.0,2.0,3.0,4.0);
        System.out.println(x);
    }   
            
    static int add (int a , int b) {
        System.out.println("this is a overloaded method #1");
        return a + b;
    }
        
    static int add (int a , int b, int c) {
        System.out.println("this is a overloaded method #2");
        return a + b + c;
    }
    
    static int add (int a , int b, int c, int d) {
        System.out.println("this is a overloaded method #3");
        return a + b + c + d;
    }
        
    static int add (double a , double b) {
        System.out.println("this is a overloaded method #4");
        return a + b;
    }

    static int add (double a ,double b, double c){
        System.out.println("this is a overloaded method #5");
        return a + b + c;
    }

    static int add (double a , double b, int c, double d) {
        System.out.println("this is a overloaded method #6");
        return a + b + c + d;
    }
}

在此处输入图像描述

要修复错误,您需要做一些事情:

  1. 在方法 4、5 和 6 中 - 将“返回类型”从int更新为double (在单词static之后的那个)
  2. 在方法 6 中 - 将参数int c更新为double c

因此,您的方法 4、5 和 6 应如下所示:

    static double add(double a, double b) {
        System.out.println("this is a overloaded method #4");
        return a + b;
    }

    static double add(double a, double b, double c){
        System.out.println("this is a overloaded method #5");
        return a + b + c;
    }

    static double add(double a, double b, double c, double d) {
        System.out.println("this is a overloaded method #6");
        return a + b + c + d;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM