Question: I'm currently studying for an exam and I found a little problem with a basic code I wrote to learn methods (I just started, I'm a newbie). 

The problem here is that I created a method called test which is supposed to do a simple product between an already stated number and another number decided by the user. I had to declare the variable of the user input as another method because it wouldn't work otherwise, so I created it before everything else and gave it value 0. The problem here is that when I use the method "test", the one which should do the product, it uses the value of the variable I stated in the beginning instead of the one that the user decided.

Here's the code:

```
import java.util.*;
import java.io.*;

public class ProvaMetodi {
    public static int numero; //User's input variable
    public static void test(){ //The problematic method
        int paolo = 23;  //I decided to multiply the user's input by this number
        int prodotto = paolo*numero; //Just a product
        System.out.println(prodotto); //Tried this, before it was an int class which 
                                     //returned the int "prodotto" so i could use it in different scenarios.
        }
        public static void main (String args []){
            Scanner gigi = new Scanner(System.in);
            System.out.println("Scrivi un numero e lo moltiplico per 23."); //Just the instructions for the user
            int numero = gigi.nextInt();
            System.out.println("Numero="+numero); //Added this for debugging purposes. The output is the user's input, so it's correct.
            test();  //here's the output, which is always 0.
        }
    }

```

Answer: 
You have two `numero` variables:

1. The first one - `int numero = gigi.nextInt();` - is the local variable inside your `main` method into which you read the user input.
2. The second one is `public static int numero;`. This one is being used by the `test` method, and its value remains `0` by default.

You'd better pass the user input to your `test` method:

```
public static void test(int numero) {
    int paolo = 23;  
    int prodotto = paolo*numero;
    System.out.println(prodotto);                     
}

```

and in `main`:

```
test(numero);

```

You can remove the static variable - `public static int numero;`.
If you want to stay with your code change 'int numero = gigi.nextInt();'
to 'numero = gigi.nextInt();'. Otherwise you are defining 'numero' locally and you do not access the global instance of 'numero'.

Take a look at Scopes and read something about it. It may help you to understand the problem.

There are many design issues in your code, but that doesn't matter as you are a beginner.

But this would be a clean approach:

```
package betahelper;

import java.util.Scanner;

class Test {
  public static void test(int numero){ //The problematic method
    int paolo = 23;  //I decided to multiply the user's input by this number
    int prodotto = paolo*numero; //Just a product
    System.out.println(prodotto); //Tried this, before it was an int class which
//returned the int "prodotto" so i could use it in different scenarios.
  }
  public static void main (String args []){
    Scanner gigi = new Scanner(System.in);
    System.out.println("Scrivi un numero e lo moltiplico per 23."); //Just the instructions for the user
    int numero = gigi.nextInt();
    System.out.println("Numero="+numero); //Added this for debugging purposes. The output is the user's input, so it's correct.
    test(numero);  //here's the output, which is always 0.
  }
}

```

As stated before changing test() to test(int).