-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
44 lines (30 loc) · 1015 Bytes
/
Copy pathSolution.java
File metadata and controls
44 lines (30 loc) · 1015 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
public class Solution {
public int[] running_sum(int[] nums) {
int n = nums.length;
int[] result = new int[n];
int runningSum = 0;
for (int i = 0; i < n; i++) {
runningSum += nums[i];
result[i] = runningSum;
}
return result;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of elements: ");
int n = input.nextInt();
int[] nums = new int[n];
System.out.println("Enter the elements of the array:");
for (int i = 0; i < n; i++) {
nums[i] = input.nextInt();
}
Solution solution = new Solution();
int[] result = solution.running_sum(nums);
System.out.println("Running Sum:");
for (int num : result) {
System.out.print(num + " ");
}
input.close();
}
}