Question: JAVA Write a void method called insertNum. insertNum is a method that takes an int array, an integer, and an index as parameters and inserts

JAVA

  1. Write a void method called insertNum.

insertNum is a method that takes an int array, an integer, and an index as parameters and inserts the integer in the given index by shifting values.

If the index is not valid, then nothing happens.

Test this method with these calls

Array

insert num

insert index

Expected array

{3, 0}

1

0

{1,3}

{5, 9, 7}

15

2

{5, 9, 15}

{5, 9, 7}

15

0

{15, 5, 9}

{5, 9, 7}

15

-1

{5, 9, 7}

{5, 9, 7}

15

3

{5, 9, 7}

Test your method by calling it from main and printing the result using your printArray from the other day.

JAVA Write a void method called insertNum. insertNum is a method that

2. 5 pt. Write a void method called insertNum. insertNum is a method that takes an int array, an integer, and an index as parameters and inserts the integer in the given index by shifting values. If the index is not valid, then nothing happens. Test this method with these calls Array insert num insert index Expected array {3,0} 1 0 {1,3} {5, 9, 7} 15 2 {5, 9, 15) {5, 9, 7} 15 0 {15, 5, 9} {5, 9, 7} 15 -1 {5, 9, 7} {5, 9, 7} 15 3 {5, 9, 7} Test your method by calling it from main and printing the result using your printArray from the other day

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!