{}
62
%OFF

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
62
%OFF

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
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