String - Exercise 1
Complete the removeWhiteSpaces() method given in the Tester class.
Method Description
removeWhiteSpaces(String str)
Remove all the white spaces from the string passed to the method and return the modified string.
Test the functionalities using the main() method of the Tester class.
Sample Input and Output
class Tester{
public static String removeWhiteSpaces(String str){
String noSpaceStr=str.replaceAll("\\s","");//usingbuiltinmethod
//Implementyourcodehereandchangethereturnvalueaccordingly
return noSpaceStr;
}
public static void main(String args[]){
String str = "Hello How are you ";
str = removeWhiteSpaces(str);
System.out.println(str);
}
}
No comments:
Post a Comment