Answer the question
In order to leave comments, you need to log in
What is the error in java array?
I declare an array, initialize it in a method, call it in the main function, and there are all zeros. Where is the mistake?
public class Not {
int[] not = new int[10000];
Random random = new Random();
public int[] notArr() {
for(int i = 0; i < not.length; i++) {
not[i] = random.nextInt(10000) + 1;
}
return not;
}
}
public class MainTest {
public static void main(String[] args) {
Not testNot = new Not();
int[] masNot = testNot.not;
System.out.println(Arrays.toString(masNot));
}
}
Answer the question
In order to leave comments, you need to log in
You didn't call the notArr method. An array is initialized to zero by default.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question