import javax.swing.*;
public class TestProject {
public static void main(String[] args) {
String test = "Hel lo !";
String[] array = new String[test.length()];
for (int a=0; a<test.length(); a++) {
array[a] = test.substring(a, (a+1));
}
NoSpaces(array);
for (int g=0; g<test.length(); g++) {
System.out.print(array[g]);
}
}
public static String[] NoSpaces(String[] theArray) {
int count=0;
for (int c=0; c<theArray.length; c++) {
if (theArray[c] == " ") {
count++;
}
}
String[] d = new String[theArray.length-count];
for (int f=0; f<(theArray.length-count); f++) {
if (theArray[f] != " ") {
d[f]=theArray[f];
}
}
return d;
}
}
I'm trying to create a program that takes a phrase constructed from user input and stores them into an array, and then to make a static method to return an array with the output being the input, except with no spaces. Here I declared a test String and stored them into an array. Then I print out the array modified by my static method. My static method includes making a new array with a length of the original String minus the spaces and only included the non-space characters. However, when I run my code, it prints the exact same thing as my input. What error did I make in my code?