K
K
Kirill Bazhenov2017-10-01 12:05:45
Java
Kirill Bazhenov, 2017-10-01 12:05:45

Array is nulled in another class and method, how to fix it?

In the Test class, the user writes data from the keyboard to the integer array Football, trying to display the value of the array in another class and method, but the array IS ZEROED! What to do?

public class Main2 {
    public static void main(String[] args) {
        Test.test();                  
        Test2.ggg();
    }
}

______________________________________
import java.util.Scanner;
public class Test {

    public static void test () {

        Scanner scan = new Scanner(System.in);

        int[] Football = new int[1];

        System.out.println("Введите количество забитых мячей");

        Football[0] = scan.nextInt();


    }

    public static  int[] Football = new int[1];

}

_______________________________________________


public class Test2 extends Test {

    public static void  ggg() {

        System.out.println("Количество забитых мячей =  "+ Football[0]);
        // Переменная Football обнуляется как это исправить?

    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question