/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package separateposneg;
/**
*
* @author Sunshine
*/
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)
{
temp=array[i];
array[pos]=temp;
pos++;
for(int k =i ; k >pos ;k--)
{
array[k]=array[k-1];
}
}
}
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]); }
}
}
No comments:
Post a Comment