Question: Java- Write a public static method named insert. The insert method should have the signature insert(String[] words, String newWord, int place), should return a String,
Java-
Write a public static method named insert. The insert method should have the signature insert(String[] words, String newWord, int place), should return a String, and should function as described below.
When called, if place does not represent a valid index for words, then the method will return a String that says "you need a valid number" to indicate the insertion could not be performed and so nothing else. Otherwise the method will insert the String newWord into the array words at the index place, moving each subsequent entry one place further and losing the final String in the array. The method will then return a concatenated string of all the words in the words array to indicate the insertion has taken place.
Use the runner class to test this method: do not add a main method to your code in the U6_L4_Activity_One.java file or it will not be scored correctly.
Sample runs (runner class):
Enter array length: 3 Enter values: one two three Enter new String: four Enter place: 1 Method return: onefourtwo Array contents: {one, four, two} Enter array length: 2 Enter values: this that Enter new String: those Enter place: 2 Method return: you need a valid number Array contents: {this, that} Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
