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