Question: my code: import java.util.Scanner; public class ArrayTools { public static int printAll(String[] input) { int len = input.length; int count = 0; if (count <
my code:
import java.util.Scanner; public class ArrayTools { public static int printAll(String[] input) { int len = input.length; int count = 0; if (count < 0) ; for (int subscript = 0; subscript < len; ++subscript) { System.out.println("[" + subscript + "]: " + input[subscript]); } return len; } public static void filter(String[] arr) { } public class Copy { 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(); } String[] destination = new String[size]; System.out.println("copy/print test 1"); ArrayTools.copy(arr, destination); ArrayTools.printAll(destination); destination = new String[size + 1]; System.out.println("copy/print test 1"); ArrayTools.copy(arr, destination); ArrayTools.printAll(destination); destination = new String[size - 1]; System.out.println("copy/print test 1"); ArrayTools.copy(arr, destination); ArrayTools.printAll(destination); destination = new String[5]; System.out.println("copy/print test 1"); ArrayTools.copy(arr, destination); ArrayTools.printAll(destination); destination = new String[size * size]; System.out.println("copy/print test 1"); ArrayTools.copy(arr, destination); ArrayTools.printAll(destination); } } public static void copy(String src[], String dest[]) { if (src.length > dest.length) { System.out.println("Error: Second array isn't big enough. First array size: " + src.length + " Second array size: " + dest.length); } else { for (int i = 0; i < src.length; i++) dest[i] = src[i]; } } class ArrayTools_2 { public static void printAll(String[] arr) { int count = 0; for (int subscript = 0; subscript < arr.length; subscript++) { if (Character.isLetter(arr[subscript].charAt(subscript))) count++; if (count >= 5) { System.out.println("[" + subscript + "]: " + arr[subscript] + " <-- Longer than five letters"); } else { System.out.println("[" + subscript + "]: " + arr[subscript]); } } } public static void filter(String[] arr) { class Demo_3 { 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();} int count = 0; for (int subscript=0; subscript < arr.length; subscript++) { if (Character.isLetter(arr[subscript].charAt(subscript))) count++; if (count > 5) arr[subscript] = arr[subscript].toUpperCase(); } } public static void printAll(String[]arr){ int count = 0; for (int subscript = 0; subscript < arr.length; subscript++) { if (Character.isLetter(arr[subscript].charAt(subscript))) count++; if (count >= 5) { System.out.println("[" + subscript + "]: " + arr[subscript] + " <-- Longer than five letters"); } else { System.out.println("[" + subscript + "]: " + arr[subscript]); } } } } } } }
PROMPT:
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.
Test Case:1
How many strings? 8ENTER: This being what the user is entering Enter a value: aaaaaaENTER Enter a value: aaaaaENTER Enter a value: aaaaENTER Enter a value: aaaENTER Enter a value: aaENTER Enter a value: aENTER Enter a value: aaaaaaaENTER Enter a value: hello world does this thing Work?ENTER [0]: AAAAAA <-- Longer than five letters [1]: aaaaa [2]: aaaa [3]: aaa [4]: aa [5]: a [6]: AAAAAAA <-- Longer than five letters [7]: HELLO WORLD DOES THIS THING WORK? <-- Longer than five letters
MY PROBLEM:
Using my code it runs well but the issue im running into is unable to figure out how to make it so once the input is above five letter it returns what was entered but in uppercase format, this is in java thank you for your time and help.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
