Originally Posted by
Newbie_96
I am studying but can't figure out what the outcome of this code will be... If you answer can you please explain what the code is saying.
final int sub = 12;
int [ ] x = new int [sub];
int y = 20;
for(int i = 0; i < sub; i++)
{
x[i] = y;
y+ = 5;
}
the meaning of that code is
1st line : you make an variable sub that have value 12
2nd line : you make an Array x with lengt alocation 12
3rd line : you make a variable y that have value 20
4th-8th line : loop for fill the value of array x for 12x loop.,.
Note : y+=5 have same meaning with y=y+5
Array started with 0 indeks
so that if you run this program in main method
public class tryAray
{
public static void main(String args [])
{
final int sub = 12;
int [ ] x = new int [sub];
int y = 20;
for(int i = 0; i < sub; i++)
{
x[i] = y;
y+ = 5;
System.out.println("X ["+i+"]= "+x[i]);
}
}
}