I'm trying to store odd numbers in an array, but when I run the code I'm getting 9, five times as answer. It's only storing the value 9.
Here are the codes:
public class Number2 {
public static void main(String[] args) {
int[] element = new int[5];
for(int i=0; i<5; i++) {
for(int j=1; j <= 10; j=j+2) {
element[i] = j;
}
}
for(int i=0; i < 5; i++) {
System.out.println(element[i]);
}
}
}
Can you tell me what's wrong with my program?