-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort012.java
More file actions
47 lines (45 loc) · 1.09 KB
/
Copy pathsort012.java
File metadata and controls
47 lines (45 loc) · 1.09 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
package array;
import java.util.Scanner;
public class sort012 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n,count0=0,count1=0,count2=0;
System.out.println("enter number of elements: ");
n=s.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=s.nextInt();
}
for(int i=0;i<n;i++)
{
if(ar[i]==0)
{
count0++;
}
else if(ar[i]==1)
{
count1++;
}
else if(ar[i]==2)
{
count2++;
}
else{
System.out.println("invalid input");
}
}
for(int i=0;i<count0;i++)
{
System.out.print("0");
}
for(int i=0;i<count1;i++)
{
System.out.print("1");
}
for(int i=0;i<count2;i++)
{
System.out.print("2");
}
}
}