Answered step by step
Verified Expert Solution
Link Copied!

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:

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Listen to minority points of view.

Answered: 1 week ago