Related questions
Concept explainers
Add a new method to ArrayTools called filter. Make this method accept a String array. Change all the Strings that are longer than 5 characters to uppercase.
ArrayTools:
public class ArrayTools
{
public static int printAll(String[] array)
{
int size= array.length;
for(int i=0;i<size;i++)
{
System.out.println("["+i+"]: "+array[i]);
}
return size;
}
Demo3 code:
import java.util.Scanner;
public class Demo3
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("How many strings?");
int size = keyboard.nextInt();
keyboard.nextLine();
String[] arr = new String[size];
for (int subscript = 0; subscript < size; subscript++)
{
System.out.println("Enter a value:");
arr[subscript] = keyboard.nextLine();
}
ArrayTools.filter(arr);
ArrayTools.printAll(arr);
}
}
Test Case 1
8ENTER
Enter a value:\n
aaaaaaENTER
Enter a value:\n
aaaaaENTER
Enter a value:\n
aaaaENTER
Enter a value:\n
aaaENTER
Enter a value:\n
aaENTER
Enter a value:\n
aENTER
Enter a value:\n
aaaaaaaENTER
Enter a value:\n
hello world does this thing Work?ENTER
[0]: AAAAAA <-- Longer than five letters\n
[1]: aaaaa\n
[2]: aaaa\n
[3]: aaa\n
[4]: aa\n
[5]: a\n
[6]: AAAAAAA <-- Longer than five letters\n
[7]: HELLO WORLD DOES THIS THING WORK? <-- Longer than five letters\n
Test Case 2
10ENTER
Enter a value:\n
doltishnessENTER
Enter a value:\n
subclassENTER
Enter a value:\n
carbonizedENTER
Enter a value:\n
myxomaENTER
Enter a value:\n
quiringENTER
Enter a value:\n
confutativeENTER
Enter a value:\n
wealdENTER
Enter a value:\n
unerringlyENTER
Enter a value:\n
unpensioningENTER
Enter a value:\n
indagativeENTER
[0]: DOLTISHNESS <-- Longer than five letters\n
[1]: SUBCLASS <-- Longer than five letters\n
[2]: CARBONIZED <-- Longer than five letters\n
[3]: MYXOMA <-- Longer than five letters\n
[4]: QUIRING <-- Longer than five letters\n
[5]: CONFUTATIVE <-- Longer than five letters\n
[6]: weald\n
[7]: UNERRINGLY <-- Longer than five letters\n
[8]: UNPENSIONING <-- Longer than five letters\n
[9]: INDAGATIVE <-- Longer than five letters\n
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
- Fill 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_forwardfill in the ? makesarrow_forwardJava Complete the method with explaining, thank you!arrow_forward
- 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_forwardpublic int[] selectionSort(int[] array) {for (int i = 0; i < array.length - 1; i++) {int min = array[i];int minIndex = i;for (int j = i + 1; j < array.length; j++) {if (min > array[j]) {min = array[j];minIndex = j;}}if (minIndex == i) {array[minIndex] = array[i];array[i] = min;}}return array;}arrow_forwardComplete the method endsInFive that takes as arguments a 2D-array of integers and an integer value that represents a column index in the array. endsInFive returns the number of values in the column that end in 5. It is possible that the array is ragged, meaning that the number of columns in each row is different. For example, 2 is returned if the following 2D-array is passed as the first argument of endsInFive and the integer 3 as the second argument (the values 25 and 115 end in five at column index 3).arrow_forward
- java Create a static method that: is called repeatAll returns ArrayList of Booleans takes in a single parameter - an ArrayList of Booleans This method should modify its ArrayList parameter by repeating its ArrayList values. For example, if the parameter is (true, false, false) The modified ArrayList should be (true, false, false, true, false, false) public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); ArrayList<Boolean> list = new ArrayList<>(); for(int i=0; i < size; i++) { list.add(in.nextBoolean()); } System.out.println(repeatAll(list)); } }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_forwardjava Create a method that: is called timesTwo returns an ArrayList of Integers takes in a single parameter - an ArrayList of Integers called nums This method should take the ArrayList parameter and multiply every value by two. public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); ArrayList<Integer> list = new ArrayList<>(); for(int i=0; i < size; i++) { list.add(in.nextInt()); } System.out.println(timesTwo(list)); } }arrow_forward
- Method Details: public static java.lang.String getArrayString(int[] array, char separator) Return a string where each array entry (except the last one) is followed by the specified separator. An empty string will be return if the array has no elements. Parameters: array - separator - Returns: stringThrows:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forwardPlease help with this java problemarrow_forwardMethods Details: public static java.lang.StringBuffer[] getArrayStringsLongerThan(java.lang.StringBuffer[] array, int length) Returns a StringBuffer array with COPIES of StringBuffer objects in the array parameter that have a length greater than the length parameter. If no strings are found an empty array will be returned. Parameters: array - length - Returns: Throws:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education