Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS FOR JAVA Given an oversize array of size words and a word to remove,write a method that returns the array with each occurrence

THIS IS FOR JAVA

Given an oversize array of size words and a word to remove,write a method that returns the array with each occurrence of thegiven word removed.

Shift the remaining words in the nonempty part of the array tothe left so that each occurrence of the given word is overwritten.(Leave the words in the empty part of the array unchanged.)

Hint: To understand the test cases, note that the size (but notthe capacity) of the array shrinks if removeWord appears in thearray. In the first test case, for example, "up" is removed and"down" and "left" shift to the left by one element. The size of thearray shrinks from 3 to 2, although the capacity is still 3. Thethird element is now in the empty part of the array. This elementis equal to "left", but it is treated as empty space.

here is the code:

import java.util.Arrays;
import java.util.Scanner;
public class RemoveOversize
{
public static void main(String[] args)
{
// Do not edit this code
Scanner keyboard = new Scanner(System.in);
final int SIZE = 20; // for the oversized array
String[] array = new String[SIZE];
// Read in data from keyboard--all array elements are presumedto be on one line
String contents = keyboard.nextLine();
String[] contentsInArray = contents.split(" ");
// Make sure we're in the range of both arrays
int index;
for(index = 0; index
{
array[index] = contentsInArray[index];
}
int arraySize = index;
String value = keyboard.nextLine(); // Get the value toremove
int resultSize = removeOversize(array, arraySize, value);
System.out.println("The resulting array contains " +Arrays.toString(array) + " and is of size " + resultSize);
keyboard.close();
}
public static int removeOversize(String[] source, intsourceSize, String removeMe)
{
// Write the code below.
return null;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

8-19. What role should job descriptions play in training at Apex?

Answered: 1 week ago