asked 202k views
3 votes
Give pseudocode for an algorithm that removes all negative values from an array, preserving the order of the remaining elements.

asked
User Dade
by
8.5k points

1 Answer

2 votes

Answer:

Begin.

WRITE ''enter test array''

READ test array

test [ ] = new_int [ ] { enter test array here, separated by comma}

int [ ] positives = Arrays.stream(test). filter(x -> x >= 0).toArray();

System. out. println( " Positive array");

for (int i : positives) {

System.out.print(i+ "\t"); }

WRITE positive array

End

Step-by-step explanation

The pseudocode for the alogirithm has been simplified above, it is implemented in Java 8

answered
User Gyro Gearless
by
7.5k points