Results 1 to 3 of 3
Thread: Array Element Problems.
- 05-15-2012, 07:45 AM #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]); }
- 05-15-2012, 08:04 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
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:
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:for (int i= 0; i < 50; i++) x[i]=1+4*i;
kind regards,Java Code:x[0]= 1; for (int i= 1; i < 50; i++) x[i]= x[i-1]+4;
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-15-2012, 04:35 PM #3
Member
- Join Date
- May 2012
- Location
- Malaysia
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
[Help] .. How To remove an element of an array ?
By Matty3z in forum New To JavaReplies: 8Last Post: 12-27-2011, 07:14 PM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM -
Max element in an Array
By mew in forum New To JavaReplies: 5Last Post: 12-03-2007, 05:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks