public class SeparatePosNeg {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int array[] = new int[]{2, -7, -6, -9, -5, 11, -19, 8, 14, 17};
int neg,pos=0, temp;
int n = array.length;
for (int i = 0; i < n; i++)
{
if (array[i] > 0)
{
// System.out.println("--)))>"+i);
temp=array[i];
array[pos]=temp;
//System.out.println("-ppp->"+pos);
pos++;
//System.out.println("-->"+pos);
for(int k =i ; k >pos ;k--)
{
// System.out.println("-->"+i);
array[k]=array[k-1];
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int array[] = new int[]{2, -7, -6, -9, -5, 11, -19, 8, 14, 17};
int neg,pos=0, temp;
int n = array.length;
for (int i = 0; i < n; i++)
{
if (array[i] > 0)
{
// System.out.println("--)))>"+i);
temp=array[i];
array[pos]=temp;
//System.out.println("-ppp->"+pos);
pos++;
//System.out.println("-->"+pos);
for(int k =i ; k >pos ;k--)
{
// System.out.println("-->"+i);
array[k]=array[k-1];
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
}
No comments:
Post a Comment