I am a beginner programmer, and I am creating this program where I would like to create a list of logical elements of size ten, and then set all values ββto false. As I understood it in Java, you should not place code directly in a class without surrounding it with a method. However, I want this to be done as soon as an instance of the class is created.
My question is where this should be done. Should I do this in the constructor, should I initialize the list with all its values, or just skip something that makes it completely fine, to put the for loop directly into the class? Thank.
Some of my code was requested, so here is the problem:
boolean[] numKeysPressed = new boolean[10];
for(int i = 0; i<10; i++){
numKeysPressed[i] = false;
}
source
share