Results 1 to 2 of 2
- 02-14-2011, 07:21 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
How do I modify the value of a single element in an array?
So i have an array that has a size that is based on the users input (order0) and the cells up to (order0-1) are all randomly generated and the last cell must be a value that when added to the sum of the (order0-1) cells equals a certain number... here is the method i am having trouble with:
public static int[] sumsarray(int s, int o){
int order0=o*2;
int sumall = 0;
int lastsum;
int sumArray[];
int lasti = order0;
//creates the one dimensional array for the sums
sumArray = new int[(order0)];
Random generator = new Random();
for (int i=0; i<(order0-1); i++){
sumArray[i] = generator.nextInt(s/order0);
}
for (int i=0; i<(order0-1); i++){
System.out.println(sumArray[i]);
}
// sums all the arrays up until the last value
for (int i=0; i<(order0-1); i++){
sumall += sumArray[i];
}
System.out.println("the sum of the first sums is:" + sumall);
lastsum = s - sumall;
System.out.println(" the last sum is:" + lastsum);
sumArray[order0]=lastsum;
return sumArray;
my question is how do i get the last sumArray value to be equal to the lastsum. thanks in advance
- 02-14-2011, 06:47 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
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 do I modify the values in an object array?
By ConMan in forum New To JavaReplies: 1Last Post: 06-02-2010, 11:26 PM -
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