-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartialSumCalculator.java
More file actions
26 lines (26 loc) · 904 Bytes
/
PartialSumCalculator.java
File metadata and controls
26 lines (26 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;
public class PartialSumCalculator{
public static void main(String[] args){
System.out.println("Please enter a set of numbers.\n");
System.out.println("Please choose the size of the set: ");
Scanner console = new Scanner(System.in);
int size =console.nextInt();
int[] numberSet = new int[size];
for(int i = 0 ; i < numberSet.length; i++){
System.out.println("Please choose element number " + (i+1));
numberSet[i] = console.nextInt();
}
int[] sumSet = sumSet(numberSet);
System.out.println("The sums set is " + Arrays.toString(sumSet));
}
public static int[] sumSet(int[] numberSet){
int[] sumSet = new int[numberSet.length];
int currSum = numberSet[0];
sumSet[0] = currSum;
for(int i = 1; i < numberSet.length; i++){
currSum = currSum + numberSet[i];
sumSet[i] = currSum;
}
return sumSet;
}
}