-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multiplication_Of_Array
31 lines (31 loc) · 1.68 KB
/
Multiplication_Of_Array
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
/* Programmer : Dhruv Patel
* Problem Name : Simple Multiplication
* Used In : Practice
* Used As : Iterative Solution
*/
package practice;
import java.util.Arrays;
import java.util.Random;
public class Multiplication {
public static void main(String[] args) {
long start_time = System.currentTimeMillis(); // Starting time of a program.
int a[]= new int[10];
Random r = new Random(); // Initializing a radom object
for(int i=0;i<a.length;i++) {
a[i] = r.nextInt(300); // Storing random numbers in an array A
}
int b[]= new int[10];
for(int m=0;m<b.length;m++) {
b[m] = r.nextInt(200); // Storing random numbers in an array B
}
int Answer[]=new int[Math.max(a.length,b.length)]; // Both Arrays are identical but, initializing a max length one
for(int k=0;k<ans.length;k++) {
Answer[k] = a[k]*b[k]; // Multiplying both arrays and storing result in an Answer array
}
System.out.print("A is : "+Arrays.toString(a)+"\t\n");
System.out.print("B is : "+Arrays.toString(b)+"\t\n");
System.out.print("Ans is : "+Arrays.toString(ans)+"\t");
long end_time = (System.currentTimeMillis()/1000)%60; // End time of a program
System.out.println("\n\nTime is : "+(end_time-start_time); // Total Time
}
}