75. JAVA Program to Suppress the Negative elements from the given Array elements.
How does this program work?
- This program is used to suppress the negative elements from the given array elements using java.
Here is the code
//To Suppress the negative elements from the given array elements
import java.util.Arrays;public class Array
{
public static void main(String[] args )
{
int array [] = { -4, 8, 6, -5, 6, -2, 1, 2, 3, -11 };
System.out.println("Array is = "+Arrays.toString(array));
int j,temp,arr_size;
arr_size = 8;
for (int i = 0; i < arr_size; i++)
{
j = i;
//Shift positive numbers left, negative numbers right
while((j > 0) && (array[j] >0) && (array[j-1] < 0)){
temp = array[j];
array[j] = array[j-1];
array[j-1] = temp;
j--;
}
}
System.out.println("New Array is=" + Arrays.toString(array));
}
}