1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Wittaler [7]
3 years ago
14

Write a public static method named insert. The insert method should have the signature insert(String[] words, String newWord, in

t place), should return a boolean, and should function as described below.
When called, if place does not represent a valid index for words, then the method will return false to indicate the insertion could not be performed and do 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 true 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.
Here is the runner code:
import java.util.Scanner;
public class runner_U6_L4_Activity_One{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter array length:");
int len = scan.nextInt();
scan.nextLine();
String[] wordList = new String[len];
System.out.println("Enter values:");
for(int i = 0; i < len; i++){
wordList[i] = scan.nextLine();
}
System.out.println("Enter new String:");
String insWord = scan.nextLine();
System.out.println("Enter place:");
int pos = scan.nextInt();
System.out.println("Method return: " + U6_L4_Activity_One.insert(wordList, insWord, pos));
System.out.print("Array contents: {");
for(int i = 0; i < len-1; i++){
System.out.print(wordList[i] + ", ");
}
System.out.println(wordList[len-1]+"}");
}
}
Computers and Technology
1 answer:
Mumz [18]3 years ago
5 0

Answer:

Explanation:

The following code was written in Java and performs the exact requirements listed in the question. It has also been tested by the runner code and works perfectly.

public static boolean insert(String[] words, String newWord, int place) {

               if (place > words.length) {

                   return false;

       } else {

                   for (int x = words.length - 1; x >= 0; x--) {

                       if (place == x) {

                           words[x] = newWord;

                           break;

                       } else {

                           words[x] = words[x-1];

                       }

                   }

                   return true;

               }

   }

You might be interested in
Jail and prison officials may generally limit inmate rights when the limitations serve
qaws [65]
Prison or jail with understanding that after a period of time,she or he   may petition the court to be released on probation. ......the release of an inmate into a  community supervision program at the discretion of the parole board within limits set  by state or federal law.

 
4 0
3 years ago
Read 2 more answers
Write a MATLAB program to accomplish the following: Create two vectors, a and b, where vector a contains all positive integers l
sattari [20]

Answer:

Explanation:

Below is the complete MATLAB code that performs the given operations.

a = 10:10:99 % Generating first vector

b = 2:2:18  % Generating 2nd vector

c = rdivide(a,b) % Dividing vector a by b and storing in c

d = times(c,c) -19 % Subtracting 19 from each element of vector c

c % Displaying value of c

d % Displaying value of d

Output screenshot

C =

 5 5 5 5 5 5 5 5 5

d =

6 6 6 6 6 6 6 6 6

3 0
3 years ago
Which data type is also called a binary object?
Andrej [43]
Binary large objects(BLOb):this data type is also called a binary object, and its fields are called binary fields.
7 0
3 years ago
Read 2 more answers
In an interview, an appropriate response to "What is an example of one of your
Vilka [71]

Answer:

"I tend to struggle with __________, because _______________.

Explanation:

For exanple:

"I tend to struggle with my anger, because I grew up in a harsh enviroment."

or

"A weakness of mine would be my self image. I was often bullied as a kid."

3 0
3 years ago
Read 2 more answers
#Write a function called "in_parentheses" that accepts a
zimovet [89]

Answer:

import regex as re

def in_parentheses(a_string):

   regeX = re.compile(".*?\((.*?)\)")

   result = re.findall(regeX, a_string)

   return str(result).replace("[","").replace("]","")

print("test 1: "+in_parentheses("Open ( only"))

print("test 2: "+in_parentheses("This is a sentence (words!)."))

8 0
3 years ago
Other questions:
  • Consider the following method.
    13·1 answer
  • While you are working with a document using a program such as wordpad, the document is stored in ___________?
    15·2 answers
  • Which of the following is used to encrypt web application data?
    11·1 answer
  • What is Administrator windows 10
    8·1 answer
  • If you're using the paintbrush tool and want to change the color of the paint being used what should you change
    6·1 answer
  • Tree diagrams are useful for
    12·1 answer
  • Which type of virus includes protective code that prevents outside examination of critical elements?
    14·1 answer
  • business information management professionals also perform duties of _ information system professionals
    11·1 answer
  • Which term describes a visual object such as a picture a table or text box
    15·2 answers
  • How ict tools changed the way we live explain it​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!