Write a function that removes all numbers from a given strin

Write a function that removes all numbers from a given string. String: 25kgm2-kmp52! v New string: kgm-kmp!v Strin th1s1ssp4rt4. New string: thssport static string RemoveNumbers (string s)

Solution

//Name this file as DeleteDigits.java, compile and run the class DeleteDigits.

import javax.swing.JOptionPane;

public class DeleteDigits {
  
public static String RemoveNumbers(String s){
String result = null;
char[] outputString = new char[s.length()];
int outIndex = 0;
  
for(int i = 0; i < s.length(); i++){
char charAtPosition = s.charAt(i);
if(Character.isDigit(charAtPosition)){
continue;
}
outputString[outIndex++] = charAtPosition;
}
result = String.valueOf(outputString);
result.trim();
return result;
}
public static void main(String args[]){
  
String inputString, outputString;
inputString = JOptionPane.showInputDialog(\"Enter the input string with digits:\");
outputString = RemoveNumbers(inputString);
JOptionPane.showMessageDialog(null, \"The given string after removing digits: \" + outputString,
\"Deleting digits within the given string\", JOptionPane.INFORMATION_MESSAGE);
}
  
}

 Write a function that removes all numbers from a given string. String: 25kgm2-kmp52! v New string: kgm-kmp!v Strin th1s1ssp4rt4. New string: thssport static st

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site