Write a Java program to arrange the elements of a given array of integers where all negative integers appear before all the positive integers.
int [] nums = new int[]{3, -2, 1, 2, 3, -6, 9, -8, -5};
for (int i = 0; i < nums.length; i++){
if(nums[i] < 0) {
System.out.print(nums[i] + " ");
}
}
for (int i = 0; i < nums.length; i++){
if(nums[i] > 0) {
System.out.print(nums[i] + " ");
}
}
Comments
Leave a comment