-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMixer.java
More file actions
99 lines (92 loc) · 2.07 KB
/
Copy pathMixer.java
File metadata and controls
99 lines (92 loc) · 2.07 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.util.*;
class Mixer
{
int arr[];
int n;
Mixer(int nn)
{
n=nn;
arr=new int[n];
}
void accept()
{
Scanner Sc=new Scanner (System.in);
System.out.println("Enter the Elements");
int count=-1;
for(int i=0;i<n;i++)
{
count++;
int count1=0;
int in=Sc.nextInt();
for(int j=0;j<count;j++)
{
if(in!=arr[j])
{
count1++;
}
}
if(count1==count)
arr[i]=in;
else if (count==n)
break;
}
}
Mixer mix(Mixer ob1)
{
int count=-1;
Scanner Sc=new Scanner (System.in);
System.out.println("Enter the length of the second array");
int a=Sc.nextInt();
int total=a+n;
System.out.println("Size:: "+total);
Mixer ob2=new Mixer(total);
for(int i=0;i<n;i++)
{
count++;
ob2.arr[count]=arr[i];
}
System.out.println("Enter the elements now");
for(int i=count+1;i<total;i++)
{
ob2.arr[i]=Sc.nextInt();
}
return ob2;
}
void sort()
{
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n-1;j++)
{
int k=0;
if(arr[i]>arr[j])
{
k=arr[i];
arr[i]=arr[j];
arr[j]=k;
}
}
}
}
void display()
{
System.out.println();
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
public static void main()
{
Scanner Sc=new Scanner(System.in);
System.out.println("Enter the n of the first array");
int n1=Sc.nextInt();
Mixer ob1=new Mixer(n1);
ob1.accept();
ob1.sort();
ob1.display();
Mixer ob2=ob1.mix(ob1);
ob2.display();
}
}