Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started