Decode School

Decode School - The School for Problem Solvers
Welcome to My Blog.
Need Assignment / Project Guidance (or) Training in Python?

Java Program to calculate sum of N given numbers

Get input n and n inputs and calculate the sum of n inputs.

Sample Input 1:

4 6 5 3 2

Sample Output 1:

The sum is: 16

Program or Solution

					    
							
					    
					

Program Explanation

Instruction(s) inside the for block{} are executed repeatedly till the second expression (j<=n) is true.

Here i is initialized to 1 and incremented by 1 for each iteration, instructions inside the for block are executed unless i becomes greater than n.

so value of num given by user will be added to sum at each iteration.

after adding all n numbers given by user to sum, sum will be printed using system.out.println.