Как извлечь из фразы специальные символы, а затем вернуть их обратно? - PullRequest
0 голосов
/ 28 ноября 2018
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);
  }  
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...