
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
![4) The following method wants to take an array of Strings and reverse the contents of each String
and store it in a new array. The method will return the resulting array.
public static String[] reverse (String[] words)
{
}
For example, if words contains: {"fire", "arose", "closing", "account", "teacher",
"java", "skirt"} the method would return the array {"erif", "esora", "gnisolc",
"tnuocca", "rehcaet", "avaj", "triks").
}
Which of the following code segments should replace /* missing code */ so that the method works as
intended?
String[] reverseWords = new String [words.length];
for (int i = 0; i < words.length; i++)
{
String temp = "";
/* missing code */
reverseWords [i] = temp;
(A)
for (int j = 0; j < words.length; j++) {
temp += words [i].substring (j, j+1);
}
}
return reverseWords;
(B)
for (int j = words [i].length(); j> 0; j--) {
temp += words [i].substring (j, j+1);
}
(C)
for (int j = 0; j < words [i].length; j++) {
temp += words [i].substring (j, j+1);
}
(D)
for (int j = words [i].length() - 1; j >= 0; j--) {
temp += words [i].substring (j, j+1);
}
(E)
for (int j = words.length() - 1; j >= 0; j--) {
temp += words.substring(j, j+1¹);](https://content.bartleby.com/qna-images/question/38e0ef70-34a2-4c97-b7a1-554a98eb604b/7a2da598-1cb2-4187-b0e6-0d5f21aaa6f5/swb0al4y_thumbnail.png)
Transcribed Image Text:4) The following method wants to take an array of Strings and reverse the contents of each String
and store it in a new array. The method will return the resulting array.
public static String[] reverse (String[] words)
{
}
For example, if words contains: {"fire", "arose", "closing", "account", "teacher",
"java", "skirt"} the method would return the array {"erif", "esora", "gnisolc",
"tnuocca", "rehcaet", "avaj", "triks").
}
Which of the following code segments should replace /* missing code */ so that the method works as
intended?
String[] reverseWords = new String [words.length];
for (int i = 0; i < words.length; i++)
{
String temp = "";
/* missing code */
reverseWords [i] = temp;
(A)
for (int j = 0; j < words.length; j++) {
temp += words [i].substring (j, j+1);
}
}
return reverseWords;
(B)
for (int j = words [i].length(); j> 0; j--) {
temp += words [i].substring (j, j+1);
}
(C)
for (int j = 0; j < words [i].length; j++) {
temp += words [i].substring (j, j+1);
}
(D)
for (int j = words [i].length() - 1; j >= 0; j--) {
temp += words [i].substring (j, j+1);
}
(E)
for (int j = words.length() - 1; j >= 0; j--) {
temp += words.substring(j, j+1¹);
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Project Description: In this project you implement an ArrayStack ADT and use the stack for implementing the following methods: a) Reverse an array of Words: Accept an array of words as input parameter and return an array of words in reverse order. Use the method signature: public static String[] reverse Words (String[] wordList) Example Input: Bird Cat Dog Elephant Output: Elephant Dog Cat Birdarrow_forwardFill in the blank to complete the following method that takes an array of integers and returns the average as a double: public static double getAverage (int[] array) { double avg = 0; for (- avg + array[1]; avg /- array.length; return avg;arrow_forwardIn C++ whats the answer from below ? int size = 10; for ( int i = -1; i < size ; i++) { arr[size - i] = i; } This array: has 12 positions is out of bounds has 10 positions has 11 positionsarrow_forward
- Complete the below function (using recursion)arrow_forwardThe following code prints out all permutations of the string generate. Insert the missing statement. public class PermutationGeneratorTester { public static void main(String[] args) { PermutationGenerator generator = new PermutationGenerator("generate"); ArrayList<String> permutations = generator.getPermutations(); for (String s : permutations) { ____________________ } } }arrow_forwardIn java, the Arrays class contains a static binarySearch() method that returns …… if element is found. false true (-k–1) where k is the position before which the element should be inserted The index of the elementarrow_forward
- Below is a bubble sort program that sorts the elements in an array. static void bubbleSort(int] arr) { arr.length; int temp = 0; for (int i = 0; i arrlil) { int n = temp arrlj- 1 arrlj - 1] = arrlil: arrli] = temp; Based on the program above, please draw a control flow graph for it. In your control flow graph, what are the test requirements for edge coverage List test path(s) that achieves the edge coverage. Provide test cases for each test path you list in the previous question. If it is not possible to find the test input for certain test path, describe the reason. In your control flow graph, what are the test requirements for edge-pair coverage? List test paths that achieve the edge-pair coverage Provide test cases for each test path you list in the previous question. If it is not possible to find the test input for certain test path, describe the reason.arrow_forward/*In this program you need to implement four methods with the following signatures:printArr(int[] a)add(int[] a, int[] b)subtract(int[] a, int[] b)negate(int[] a) 1. Method printArr(a) should print out all elements of a given int array in one line. 2. Method add(a, b) should take two int arrays (assume they have the same length) and return a new array each element of which will be the sum of the corresponding elements in a and b 3. Method subtract(a, b) is similar to add(), except it returns (a - b) array 4. Method negate(a)takes an int array and returns a new array in which every element is multiplied by -1. */ public class ArrayOperations{ public static void main(String[] args){ //The main only has the testing code. //You don't have to change it. int [] a = { 1, 2, 3, 4, 5}; int [] b = {10, 1, 3, 5, 7}; System.out.print("a = "); printArr(a);//Should print each element of a (in one line) System.out.print("b = ");…arrow_forwardRefer to the following method that finds the smallest value in an array. /** Precondition: arr is initialized with int values. * Oparam arr the array to be processed Greturn the smallest value in arr public static int findMin(int[] arr) { int min = /* some value */; int index = 0; while (index < arr.length) { if (arr [index] < min) min = arr [index]; index++; } return min; } Which replacement(s) for /* some value */ will always result in correct execu- tion of the findMin method? I Integer.MIN_VALUE II Integer.MAX_VALUE III arr [0] (A) I only (B) II only (C) III only (D) I and III only (E) II and III onlyarrow_forward
- Write the following method that returns the sum of all numbersin an ArrayList:public static double sum(ArrayList<Double> list)Write a test program that prompts the user to enter five numbers, stores them inan array list, and displays their sum.arrow_forwardclass Output{public static void main(String args[]){byte a[] = { 65, 66, 67, 68, 69, 70 };byte b[] = { 71, 72, 73, 74, 75, 76 };System.arraycopy(a , 0, b, 0, a.length);System.out.print(new String(a) + " " + new String(b));}} The output of the above Java code is ?arrow_forward1. Write a program that calls a method that takes a character array as a parameter (you can initialize an array in the main method) and returns the number of vowels in the array. Partial program is given below. public class CountVowels{ public static void main(String[] args){ char[] arr= System.out.print("There are "+vowels(arr)+" vowels in the array");arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education