Hi
suppose i've
int[] nos = new int[]{1 to 10};
and
int[] sum;
then i want
for(i =0 i{
sum[i] = (sum of all nos other than i)
}
how to get ..
plz reply..
Printable View
Hi
suppose i've
int[] nos = new int[]{1 to 10};
and
int[] sum;
then i want
for(i =0 i{
sum[i] = (sum of all nos other than i)
}
how to get ..
plz reply..
Hello
Try this:
Hope this does the trick! ;)Code:int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] sums = new int[numbers.length];
for (int i = 0; i < numbers.length; i++){
int sum = 0;
for (int j = 0; j < numbers.length; j++){
if (numbers[j] != numbers[i]){
sum += numbers[j];
}
}
sums[i] = sum;
}