This will fill the array with a range of 1 - N
:
public class NurTests {
public static void main(String[] args) {
int [] arr = new int[100];
int value = 1;
for(int i = 0; i < arr.length; i++){
arr[i] = value;
value ++;
}
}
}
A simpler way to do it, you could just remove the middle man:
public class NurTests {
public static void main(String[] args) {
int [] arr = new int[100];
for(int i = 0; i < arr.length; i++){
arr[i] = i + 1;
}
}
}
1
solved Java Filling array with numbers from 1 to X with a loop (not random numbers) [duplicate]