# Java Programming | Multiplication of numbers in array

Introduction

This is tutorial for multiplication of numbers in arrays. The program is given below that takes numbers from user and saves them in array and multiplies the numbers and print it. The program is not extendable. Go enjoy the program. Lets begin…..

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

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

//Declare input as scanner
Scanner input = new Scanner(System.in);

//Take input for arrays
for(i=0;i<5;i++)
{
System.out.println("Enter Number :");
a[i] = input.nextInt();
}

//add the numbers from arrays
for(i=0;i<5;i++)
multi=multi*a[i];

//print the sum
System.out.println("Product = "+multi);
}
}
``````

Output

Enter Number :
1
Enter Number :
2
Enter Number :
3
Enter Number :
4
Enter Number :
5
Product = 120

How does it work

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

Extending it

The program cannot be extended.

Explanation.

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 product.
9. Add system.out.println() function to print product

At the end.

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

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

Sharing options: