Answer:
public class num2 {
public static String removeSpaces(String word){
String wordNoSpaces = word.replaceAll(" ","");
return wordNoSpaces;
}
public static void main(String[] args) {
String str = "Hello my name is John";
System.out.println(removeSpaces(str));
}
}
Explanation:
Using Java Prograamming language
- Define the method removeSpaces() to accept a string as parameter and return a string as well
- With the method's body, use Java's built-in method replaceAll() to replace all whitespaces with no spaces String wordNoSpaces = word.replaceAll(" ","");
- Return the resulting string
- In the main method define a string with white spaces
- Call removeSpaces and pass the defined string as an argument
- Output the result