Problem with Methods and Arguments JAVA

0

I have a method x that receives an entire parameter, and I have a method z which, in order to work, uses the x method.

My problem is that they require me not to use global variables. Therefore, I can not ask the x method parameter and save it in a variable and then use it in the z

method

Would anyone know of any way to do it as required?

    
asked by Enrique 01.10.2017 в 19:12
source

2 answers

1

By global variable means you mean a static .

Instead, you can occupy a class attribute in which you assign the value of the X method parameter, and then retrieve it in the Z method. . p>

private int x;

private void metodoZ(){
    metodoX(10);
    System.out.println(this.x); // Imprimirá 10 en consola
}

private void metodoX(int parametro){
    this.x = parametro;
}
    
answered by 02.10.2017 / 19:55
source
0

ret will contain the multiplo of 10;

int ret = metodoZ(10);

public int metodoZ(int param){
    int u;
    u = metodoX(param);

    return u
}

public int metodoX(int parametro){
    int i;
    i = parametro * 10;

    return i;
}
    
answered by 01.10.2017 в 20:08