Advertisement
Guest User

MorseCode

a guest
Nov 19th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Morse {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. String morse[] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..",
  7. "--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..",
  8. "|",".---","..---","...--","....-",".....","-....","--...","---..","----.","-----"};
  9. char Alphabet [] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  10. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' '};
  11.  
  12. String input = scanner.nextLine();
  13. String[] text = input.split("\\s+");
  14.  
  15.  
  16. String newText = "";
  17.  
  18.  
  19.  
  20. for (int i = 0; i < text.length; i ++){
  21.  
  22. for (int j = 0; j < morse.length; j ++){
  23. if (text[i] == morse[j]){
  24. newText+= Alphabet[j];
  25. }
  26. }
  27. }
  28. System.out.println(newText);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement