Java: Arrange the elements of a given array of integers where all negative integers appear before all the positive integers
Write a Java program to arrange the elements of an array of integers so that all negative integers appear before all positive integers.
Pictorial Presentation:
Sample Solution:
Java Code:
Sample Output:
Original Array: [-4, 8, 6, -5, 6, -2, 1, 2, 3, -11] New Array: [-4, -5, -2, -11, 6, 6, 1, 2, 8, 3]
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to rearrange an array such that even numbers appear before odd numbers.
- Write a Java program to rearrange an array such that numbers with absolute values greater than a given threshold appear firt.
- Write a Java program to rearrange an array such that elements are possitioned alternatively as positive and negative numbers.
- Write a Java program to move all zeros in an array to the end while maintaining the order of non-zero elements.
Java Code Editor:
Previous: Write a Java program to find the rotation count in a given rotated sorted array of integers.
Next: Write a Java program to arrange the elements of a given array of integers where all positive integers appear before all the negative integers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.