Skip to content
Advertisement

How to create an array with random numbers and send it to listener without randomizing it again?

So i’m trying to create a program that create an array of 100 random numbers (without changing everytime user reacts to it), and allow users to check the numbers by entering the index of it. However, the array keep randomizing everytime the user pressed the Show Element button.

I also tried to create the array on the main program, but I then faced the error because the listener can’t access the array. Please enlighten me as I’m new to this Java GUI Programming. Any help is much appreciated.

JavaScript

Advertisement

Answer

In the constructor you are assigning the random numbers to a local variable arr that is overriding the private attribute arr with the same name

Try changing it to:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement