fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. morseToEnglish("... ---");
  13. System.out.println("======");
  14. morseToEnglish("...|---");
  15. }
  16.  
  17.  
  18.  
  19. public static void morseToEnglish(String morseSentence) {
  20.  
  21. String englishArray[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
  22. String morseArray[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".--- ", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
  23.  
  24.  
  25. String[] words = morseSentence.split("[|]");
  26.  
  27. for (String word: words) {
  28.  
  29. String[] morseChars = word.split("\\s");
  30.  
  31.  
  32. for (String morseChar : morseChars) {
  33.  
  34. if (morseChar.isEmpty()) { continue; }
  35.  
  36. for (int i = 0; i < morseArray.length; i++) {
  37.  
  38. if (morseChar.equals(morseArray[i])) {
  39.  
  40. System.out.println(englishArray[i]);
  41.  
  42. //newEnglishChar = englishArray[i];
  43. //translatedText = translatedText + newEnglishChar;
  44. }
  45. }
  46. }
  47. }
  48. //System.out.println(translatedText);
  49. }
  50.  
  51. }
Success #stdin #stdout 0.07s 2841600KB
stdin
Standard input is empty
stdout
s
o
======
s
o