# Write code to output the no. of times each number appears in two unsorted arrays

Given two strings of unsorted integers write code to output the no. of times each number appears in both arrays. In the sample below number 2 appears 3 times
Sample Arrays:
array #1 [2,21,4,56,12,10,8,2,12,10,21]
aray #2 [12,8,2,10,56,12,8,8,12,4,12]

#### preet

• Sep 19th, 2017

```Codepublic class RepeationTimes {

public static void main(String[] args) {
@SuppressWarnings("unused")
int num1[]= new int[] {2,21,4,56,12,10,8,2,12,10,21};

@SuppressWarnings("unused")
int num2[]=new int[]{12,8,2,10,56,12,8,8,12,4,12};
int c=0;

for (int i=0;i<num1.length;i++){
for (int j=0;j<num2.length;j++){
if (num1[i]==num2[j]){
c++;
}

}
System.out.println(num1[i]+ " "+" "+"Repeated "+c+" times");
c=0;
}

}
}
```

#### Ashwary Naveen

• Jan 15th, 2018

Ans

```Codepackage temp;

public class Exp {
public static void main(String[] args) {
int num1[]= new int[] {2,21,4,56,12,10,8,2,12,10,21};
int num2[]=new int[]{12,8,2,10,56,12,8,8,12,4,12};
int max = num1;
for(int i=0;i<num1.length-1;i++){
if (max < num1[i+1]){
max = num1[i+1];
}
}
for(int i=0;i<num2.length-1;i++){
if (max < num2[i+1]){
max = num2[i+1];
}
}
int out[] = new int[max+1];
for(int i=1;i<=out.length;i++){
for(int j=0;j<num1.length;j++){
if(i==num1[j])
out[i] = out[i] + 1;
if(i==num2[j])
out[i] = out[i] + 1;
}
}
for(int i=1;i<=max;i++){
if(out[i]>0)
System.out.println("num "+i+ " comes "+out[i]+" times.");
}
}
}
```

#### Rita

• May 10th, 2018

Write code to output the no. of times each number appears in two unsorted arrays

```Codepublic class ArrayCountRepNo {
public static void main(String args[]) {
int[] num1 = { 2, 21, 4, 56, 12, 10, 8, 2, 12, 10, 21 };
int[] num2 = { 12, 8, 2, 10, 56, 12, 8, 8, 12, 4, 12 };
int counter = 0;
for (int i = 0; i < num1.length; i++) {
for (int k = 0; k < num1.length; k++) {
if (num1[i] == num1[k]) {
counter++;
}
}
for (int j = 0; j < num2.length; j++) {
if (num1[i] == num2[j]) {
counter++;
}

}
System.out.println(num1[i] + " " + " " + "Repeated " + counter
+ " times");
counter = 0;

}

}
}```  