1. Member
Join Date
May 2012
Location
Malaysia
Posts
3
Rep Power
0

## Array Element Problems.

Hi...

I have question on how to put value or element in array that its value is increment of previous element. I have created 50 array and need to fill it with this example of data:

1,5,9,13,17,21 and so on..(increment of 4)

Java Code:
```public static void main(String args[]){

int x[] = new int[50];

for(int i=0; i<=49; i++)
System.out.println("x["+i+"] = "+x[i]);

for(int i=0; i<=49;i++)
x[i] = i;

for(int i=0; i<=49; i++)
System.out.println("x["+i+"] = "+x[i]);

}```

2. ## Re: Array Element Problems.

Draw two axes, an X axis that represents the index value (i.e. 0,1,2,3 etc) and a Y axis that representsa the corresponding values (i.e. 1,5,9,13 etc.) That makes a straight line f(x) == 1+4*x. The x value is the index and the f(x) value is the value of the array element; subtituting i for x makes:

Java Code:
```for (int i= 0; i < 50; i++)
x[i]=1+4*i;```
This is geometric interpretation; you can also solve it algebraically: every element of the array is four more than the elements to its left. The first element equals one; so:

Java Code:
```x[0]= 1;
for (int i= 1; i < 50; i++)
x[i]= x[i-1]+4;```
kind regards,

Jos

3. Member
Join Date
May 2012
Location
Malaysia
Posts
3
Rep Power
0

## Re: Array Element Problems.

thank you very much..before this i try something like this x[i] = i =+4 but apparently does not work out..your method however works and thank you again for your guidance..