-
Notifications
You must be signed in to change notification settings - Fork 7
/
Q4Sort012.java
50 lines (48 loc) · 1.11 KB
/
Q4Sort012.java
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
package array;
import java.util.Scanner;
public class Q4Sort012 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter the size of Array: ");
int size=sc.nextInt();
int arr[]=new int[size];
System.out.print("Enter the values of the Array: ");
for(int i=0;i<arr.length;i++){
arr[i]=sc.nextInt();
}
sort(arr,size);
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]);
System.out.print(" ");
}
}
static void sort(int arr[],int size){
int zc=0;
int c1=0;
int c2=0;
for(int i=0;i<size;i++){
if(arr[i]==0){
zc++;
}
else if(arr[i]==1){
c1++;
}
else{
c2++;
}
}
int j=0;
while(zc-->0){
arr[j]=0;
j++;
}
while(c1-->0){
arr[j]=1;
j++;
}
while(c2-->0){
arr[j]=2;
j++;
}
}
}