Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

array contains zeros and ones as elements.we need to bring
zeros one side and one other side in single parse.
ex:a[]={0,0,1,0,1,1,0,0}
o/p={0,0,0,0,0,1,1,1}

Answer Posted / anon

import java.util.Arrays;


public class Exps {

public static void array_0s_1_seprator(int[] arr){
System.out.println("Orignal Array : " + Arrays.toString(arr));
for(int i = 0, j =arr.length ; i< j ;++i ){

if(arr[i]==0) continue;

while(arr[--j]==1 && i<j)
continue;
if(i< j){
arr[i] = 0;
arr[j] = 1;
}
System.out.println("Modified Array : " + Arrays.toString(arr));
}
}

public static void main(String[] args) {
int arr[] = new int[15];
for(int i =0; i<arr.length;++i)
arr[i] = (int)(Math.random()*10) <5 ? 0 : 1;
array_0s_1_seprator(arr);
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When c language was developed?

1049


Which is better pointer or array?

1010


Explain how do you print only part of a string?

1199


What is string constants?

1137


Give basis knowledge of web designing ...

2008


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

1059


a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

1253


Which type of language is c?

1065


What is the benefit of using const for declaring constants?

1037


how can use subset in c program and give more example

1979


I need previous papers of CSC.......plz help out by posting them.......

2278


What is static volatile in c?

1012


What is typeof in c?

993


Is fortran still used today?

1083


What are the types of unary operators?

1172