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
-
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.

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
Get step-by-step solutions from verified subject matter experts
