{}
BLACK NOVEMBER
Get 83% off PRO
Are you struggling to build your coding confidence or land your first job?
Fast-track to your first pay-check.
Start FREE trial →
Start FREE trial →
BLACK NOVEMBER
Get 83% off PRO
Are you struggling to build your coding confidence or land your first job?
Fast-track to your first pay-check.
Start FREE trial →
Start FREE trial →
run-icon
Main.java
class Sortarray { public static void main(String[] args) { int arr[]={0,1,1,0,0,1,0,1,0}; int n=arr.length; int noOfZeros=0; int noOfOnes=0; for(int i=0; i<n; i++){ if(arr[i]==0) noOfZeros++; else noOfOnes++; } for(int i=0; i<n; i++){ if(i<noOfZeros) arr[i]=0; else arr[i]=1; } for(int ele:arr){ System.out.print(ele+" "); } } }
Output