0

I understand that no such thing exists, but I know that you can do something like that with wrapper classes (?). I also can't use the return statement to return an array or anything. (It's for a university practice).

This is the code I have:

//This is the main:
calculadoraMax.devolverParametros(v, min, max, promedio);
System.out.println("min: " + min + " max: " + max + " promedio: " + promedio);

public static void devolverParametros(int[] v, Integer min, Integer max, Double promedio) {
    for (int i = 0; i < v.length; i++) {            

        if(v[i] > max) {
            max = v[i]; 
        }           

        if(v[i] < min) {
            min = v[i];
        }   

        promedio = promedio + v[i];
    }
}

I basically need to get "min", "max" and "promedio" to get modified in devolverParametros and be returned to the main.

I have already tried declaring the types of the variables both as Wrapped classes and native classes.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

0

Java is pass-by-value (Please read Is Java "pass-by-reference" or "pass-by-value"?), hence you need move these variable to class level for that. Here's a link see if this is helpful to you : https://stackoverflow.com/a/71553502/1643891

Sup19
  • 88
  • 10
  • Thanks, i created an object with the parameters i needed and passed an instance of that object to the method and it worked. – Nicolas Panico Mar 24 '22 at 14:55