Question: Use Java 8. Copy the positive elements of A to B, but in reverse order, stopping upon encountering a negative element. Assume that code was

Use Java 8. Copy the positive elements of A to B, but in reverse order, stopping upon encountering a negative element. Assume that code was written to fill array A.

Here is my code, but it did not pass the test set up by my teacher:

Use Java 8. Copy the positive elements of A to B, but

public class Backwards { private int [] A, B; public Backwards () { A = new int [100]; B = new int [100]; //hidden code fills A /** * Copies positive elements of A to B, but in reverse order, stopping upon encountering a negative element. */ public void backwardsCopy () { int i, j, k = 0; for(i = 0; A[i] > 0; i++); { for(j = i-1; j >= 0; j--) { B[k] = A[j]; k += 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!