I need to take an Array with 10 int and initialize them all to 0. Then I need to write a For loop that changes all their values to range 10-100 counting by tens. Then another For loop to print them all. How do I make them count by ten? and how do I print them in the second loop?
int i
int[] numsTen= new int [10];
numsTen[0]= 0;
numsTen[1]= 0;
numsTen[2]= 0;
numsTen[3]= 0;
numsTen[4]= 0;
numsTen[5]= 0;
numsTen[6]= 0;
numsTen[7]= 0;
numsTen[8]= 0;
numsTen[9]= 0;
for (i=10; i<100; i+10) {
numsTen[i]=i;
for (i = 0; i=numsTen; i+10) {
System.out.print(numsTen[] + " ");;
}
}
}
}
>Solution :
Here is the corrected code:
int i;
int[] numsTen = new int [10];
for (i = 0; i < 10; i++) {
numsTen[i] = i * 10 + 10;
}
for (i = 0; i < 10; i++) {
System.out.print(numsTen[i] + " ");
}
In the first for loop, the value of i is used as the index for the numsTen array, and the value of i * 10 + 10 is assigned to that index. This effectively increments the value of numsTen[i] by 10 for each iteration of the loop, starting from 10.
In the second for loop, the value of i is again used as the index for the numsTen array, and the value of numsTen[i] is printed for each iteration of the loop.