-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFindSameElement.java
More file actions
62 lines (38 loc) · 860 Bytes
/
FindSameElement.java
File metadata and controls
62 lines (38 loc) · 860 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package pack1;
import java.util.Random;
public class Arrays {
public static void list(int[] array, int length){
for(int i=0; i<5;i++)
{
System.out.print(array[i]+" ");
}
System.out.println();
}
public static void main(String[] args)
{
int[] array1=new int[5];
int[] array2=new int[5];
String str="";
Random rnd=new Random();
for(int i=0;i<5;i++)
{
array1[i]=rnd.nextInt(11)+10;
array2[i]=rnd.nextInt(11)+10;
}
list(array1,array1.length);
list(array2,array2.length); //İnstead of below for
int i,j;
for(i=0;i<5;i++)
{
for (j=0;j<5;j++)
{
if (array1[i]==array2[j])
{
System.out.print(array1[i]+" ");
str+=array1[i]+" ";
}
}
}
System.out.println(str);
}
}