I try to create a Java program with GUI and I want one button to generate random numbers and other buttons just do some operations on those random numbers. Currently the size of random number are fixed but in the future the size will be determined by user input. So I decide to use switch-case. It looks like each case has own scope. If I create an array in case 1. I can not reach the array in case 2. I wonder if there are other solutions except creating a globe array. Thanks for the time.
int [] data = new int[100];
switch (index){
case "1":
//create array full fill with random number
for (int i = 0; i< 100; i++){
data[i] = (int)(Math.random()*(10*100));
}
break;
case "2":
//sort the array
sort.(data);
break;
default:
System.exit(0);
}