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
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 now
This is a popular solution!
Step by step
Solved in 3 steps