Write a program to print Running Sum using for loop
You will be given a number n of integer data-type.
After this you will be given n integers as input of integer data-type, and you have to print the sum after you take input of an integer each time.
Initially the sum is zero.
Input Format
For each test case, You will get the value n as an integer input in the first line,
and n integers as intger input in different lines.
Constraints
0<=n<=2^10 -2^31<=Each integer input<=2^31-1
Output Format
You have to print the running sum, each time in a different line.
Sample Input 0
5
3
2
2
-1
4
Sample Output 0
3
5
7
6
10
Explanation 0
In the first line we receive 5, means five integer inputs will be given as input.
Initially before taking any integer input the sum is zero.
When we take in the first integer input which is 3, sum becomes 3.
When we take in the second integer input which is 2, sum becomes 5.
After 3rd input, sum becomes 7.
After 4th input, sum becomes 6,
After 5th input, sum becomes 10.
Sample Input 1
6
2
3
1
4
5
-9
Sample Output 1
2
5
6
10
15
6
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int sum=0;
int avg=0;
for(int i=1; i<=n; i++){
int num=sc.nextInt();
sum=sum+num;
System.out.println(sum);
}
}
}