Write a program to enter a string and reprint it after removing all numbers and blank spaces in java .io.*
Answers
Answer:
if you satisfied with my answer please mark me as a brainlist answer an follow me
Explanation:
public class RemoveAllSpace { public static void main(String[] args) { String str = "India Is My Country"; //1st way String noSpaceStr = str.replaceAll("\\s", ""); // using built in method System.out.println(noSpaceStr); //2nd way char[] strArray = str.toCharArray(); StringBuffer stringBuffer = new StringBuffer(); for (int i = 0; i < strArray.length; i++) { if ((strArray[i] != ' ') && (strArray[i] != '\t')) { stringBuffer.append(strArray[i]); } } String noSpaceStr2 = stringBuffer.toString(); System.out.println(noSpaceStr2); } }
Answer:
string = "Once in a blue moon";
ch = '-';
#Replace space with specific character ch
string = string.replace(' ', ch);
print("String after replacing spaces with given character: ");
print(string);
Explanation:
hope it helps you please follow me