- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunSum1d.java
More file actions
Latest commit
19 lines (19 loc) · 522 Bytes
/
Copy pathRunSum1d.java
File metadata and controls
19 lines (19 loc) · 522 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
publicclassRunSum1d {
publicint[] runningSum(int[] nums){
intsum = 0;
int[] arr = newint[nums.length];
for(inti = 0; i < nums.length; i++){
sum+=nums[i];
arr[i] = sum;
}
returnarr;
}
publicstaticvoidmain(String[] args){
int[] array = {1,2,3,4};
RunSum1dobj = newRunSum1d();
int[] a = obj.runningSum(array);
for(inti = 0; i < a.length; i++){
System.out.print(a[i] + " ");
}
}
}