Java Programming | Addition of Numbers from array


This is a tutorial for addition of numbers from array. The program is given below that takes numbers from user and save them in array and adds them. The program is not extendable. Go enjoy the program. Lets begin…….

Program for addition of numbers from array.

//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class ArrayAdd {
	//void main
		public static void main (String[] args)
			//declare int
			int i,a[] = new int[10],sum=0;

			//Declare input as scanner
			Scanner input = new Scanner(;

			//Take input for arrays
			 System.out.println("Enter Number :");
			 a[i] = input.nextInt();

			//add the numbers from arrays

			//print the sum
			System.out.println("Sum = "+sum);


Enter Number :
2Enter Number :

Enter Number :
Enter Number :
Enter Number :
Sum = 15

How does it work

  1. You enter the number.
  2. The number is saved in respective array.
  3. The numbers from arrays are added.
  4. The sum is printed.

Extending it

The program cannot be extended.


  1. Import the Scanner.
  2. Declare the class as public
  3. Add the void main function
  4. Declare input as Scanner.
  5. Add a for loop.
  6. Add system.out.println() function with the message to enter number.
  7. Take the inputs and save it in arrays.
  8. Add one more loop to calculate sum.
  9. Add system.out.println() function to print sum.

At the end.

You learnt creating the Java program for Addition of numbers from arrays. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Join India's Largest Code Learning Community on Get it on Google Play
Sharing options: