
Write a static method named "bigBeforeSmall" that accepts an array of Strings as a parameter and rearranges its elements so that longer Strings appear before shorter Strings. For example, if the following array is passed to your method:
String[] numbers = { "one", "twelve", "three", "four", "fourteen", "six" };
Then after the method has been called, one acceptable ordering of the elements would be:
["fourteen", "twelve", "three", "four", "one", "six" ]
The exact order of the elements does not matter, so long as all longer Strings appear before all shorter Strings. Another acceptable order would be:
["fourteen", "twelve", "three", "four", "six", "one" ]
Do not make any assumptions about the length of the array or the range of values it might contain. For example, the array might contain empty Strings (length zero), or all Strings could have the same length. You may assume that the array is not null (empty).
Hint: This is actually a sorting problem. In BubbleSort you tested pairs of elements and swapped them if the left element is larger than the right element. In this problem, the swap happens when the left element has fewer characters than the right element.
You also may not use any other data structures such as the ArrayList class from Chapter 10.
DO NOT use Arrays.sort in your solution.
You may use the following code to test your program:
If your method is modeled after a bubble sort, expected output is:
["fourteen", "twelve", "three", "four", "one", "six" ]
import java.util.*;
public class BigOnesFirst {
public static void main(String[] args) {
String[] numbers = {"one", "twelve", "three", "four", "fourteen", "six"};
bigBeforeSmall(numbers);
System.out.println(Arrays.toString(numbers));
}
// *** Your method code goes here ***
} // End of BigOnesFirst class

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

- Write a program called Range_array.java that has a method with one integer array and two integers position1 and position2 as parameters, where 0<=position1<=position2<=a.length-1. The method should construct and return an array that is identical to the given array, but with the values in position1 through position2 deleted. The output should look exactly like what is pictured below please. The code must be editable, and all variables defined within please.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_forwardThe programming language used is Javaarrow_forward
- Write a class ArrayClass, where the main method asks the user to enter the four numbers. Create a method printArray that prints the array whenever required (use Array.toString method). Make the program run as shown in the Sample Run below. Use Array.sort, Arrach.bianrySearch, Array.equalsarrow_forwardWrite a method that takes a rectangular two-dimensional array of type int. The method returns true if the sum of the even elements of the parameter array are larger than the sum of the odd elements, otherwise the method returns false. public static boolean sum(int[]0 in) Taken array Result 1 -3 17 5 -2 30 true 1 3 -1 -1 -3 -4 7 -1 10 false -1 3 -4 15arrow_forwardA method named getUserStringsAndPopulate Array(). This method should keep prompting the user to enter as many strings as the user wants. The user should be able to stop entering strings by entering EXIT. This method should take the strings entered by the user and populate a one-dimensional array of strings with the user input. The string EXIT should NOT be added to the array because it is a special flag that will tell the method to stop prompting the user to enter more strings. This method should return the one-dimensional array of strings populated with user input and should not accept any arguments. 2.b) A method named searchArray() that would accept a one-dimensional array of strings and search the array for the string Winter. The search logic should NOT be case sensitive. If a match is found, this method should print the string in the array followed by a message like " --- Found a match!". Otherwise, the method should not print anything. This method should NOT return anything.…arrow_forward
- 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





