Write method findZero, as started below.  findZero should return the index of the first element of array A that contains the value zero, starting from position 0 up through position  pos.  If no element of A from position 0 to position pos contains the value zero, then findZero should return –1.  For example: Array (A) Position (pos) Value returned by findZero(A, pos) 1 0 2 5 6 0 -1 1 0 2 5 6 1 1 1 0 2 5 6 2 1 1 0 2 0 6 2 1 1 0 2 0 6 4 1 1 2 3 4 5 4 -1 Complete method findZero below.  Assume that it is called only with values that satisfy its assumptions as stated below.    // Description: Returns smallest index k // such that (0 <= k <= pos) and (A[k] == 0) // Assumptions: 0 <= pos < A.length public int findZero(int[] A, int pos) {

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

Write method findZero, as started below.  findZero should return the index of the first element of array A that contains the value zero, starting from position 0 up through position  pos.  If no element of A from position 0 to position pos contains the value zero, then findZero should return –1.  For example:

Array (A)

Position (pos)

Value returned by

findZero(A, pos)

1 0 2 5 6

0

-1

1 0 2 5 6

1

1

1 0 2 5 6

2

1

1 0 2 0 6

2

1

1 0 2 0 6

4

1

1 2 3 4 5

4

-1

Complete method findZero below.  Assume that it is called only with values that satisfy its assumptions as stated below. 

 

// Description: Returns smallest index k

// such that (0 <= k <= pos) and (A[k] == 0)

// Assumptions: 0 <= pos < A.length

public int findZero(int[] A, int pos) {

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,