public static String keepLetters(String word){
String lettersOnly = ""; //variable for letters only
//loop to go to throught the whole code
for (int i = 0; i < word.length(); i = i + 1){
char letter = word.charAt(i); // get the ascii code
int ascii = (int)letter;
// check if the letter is A to Z
if (ascii >= 65 && ascii <= 90 || ascii >= 97 && ascii <= 122 ){
lettersOnly = lettersOnly + letter; // keep it if it is
}}
return lettersOnly; // return just the letters
}
public static void main(String[] args) {
String input = "", justLetters = "";
input = JOptionPane.showInputDialog(null, "Enter a word or phrase");
justLetters = keepLetters(input);
JOptionPane.showMessageDialog(null, "The phrase with only letters is: " + justLetters);
}
}