Math, asked by shivaninandani2407, 10 months ago

Find sum of all other elements in an array in the input will be comma seperated strring

Answers

Answered by Anonymous
0

Step-by-step explanation:

The simplest way to convert an array to comma separated String is to create a StringBuilder, iterate through the array, and add each element of the array into StringBuilder after appending comma. You just need Java 1.5 for that, even if you are not running on Java 5, you can use StringBuffer in place of StringBuilder.

Answered by Anonymous
2

Answer:

For every i,

arr[i] = sumOfArrayElements – arr[i]

Step-by-step explanation:

Input: arr[] = {5, 1, 3, 2, 4}

Output: 10 14 12 13 11

Original array {5, 1, 3, 2, 4}

Encrypted array is obtained as:

= {1+3+2+4, 5+3+2+4, 5+1+2+4, 5+1+3+4, 5+1+3+2}

= {10, 14, 12, 13, 11}

Each element of original array is replaced by the

sum of the remaining array elements.

Input: arr[] = {6, 8, 32, 12, 14, 10, 25 }

Output: 101 99 75 95 93 97 82

Similar questions