Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- char[] letters = { ' ', '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',};
- String[] morseLetters = { " ", ". ___", "___ . . .", "___ . ___ .", "___ . .", ".", ". . ___ .", "___ ___ .", ". . . .", ". .", ". ___ ___ ___", "___ . ___", ". ___ . .", "___ ___", "___ .", "___ ___ ___", ". ___ ___ .", "___ ___ . ___", ". ___ .", ". . .", "_", ". . ___", ". . . ___", ". ___ ___", "___ . . ___", "___ . ___ ___", "___ ___ . ."};
- String textToChange = "";
- String newText = "";
- System.out.println("Enter text you want to change to Morse code");
- textToChange = input.nextLine();
- textToChange = textToChange.toLowerCase();
- for (int i = 0; i < textToChange.length(); i++) {
- for (short j = 0; j < 26; j++) {
- if (textToChange.charAt(i) == letters[j]) {
- newText += morseLetters[j];
- newText += " ";
- break;
- }
- }
- }
- System.out.println("Text in Morse Code");
- System.out.println(newText);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement