简体   繁体   中英

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

if you are replying pls show me code and tips the code comes from bro code and im still learnin sorry

i have fixed a couple of other errors but it still doesn't work

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;
    }
}

enter image description here

To fix the errors, you need to do a few things:

  1. In methods 4, 5, and 6 - update the "return type" from int to double (the one which goes after the word static )
  2. In method 6 - update the parameter int c to double c

So your methods 4, 5, and 6 should look like this:

    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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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