Skip to content

Instantly share code, notes, and snippets.

@kraksy
Created September 21, 2023 15:47
Show Gist options
  • Save kraksy/34ba2e1b683c8f77c5e0d160e88f700f to your computer and use it in GitHub Desktop.
Save kraksy/34ba2e1b683c8f77c5e0d160e88f700f to your computer and use it in GitHub Desktop.
homework for tommorow
import java.util.Scanner;
public class Main {
public static void main(String[] args){
char[] english = { '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', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
',', '.', '?' };
String[] morse = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".---.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----",
"..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.",
"-----", "--..--", ".-.-.-", "..--.." };
Scanner scanner = new Scanner(System.in);
System.out.println("enter user input <string> : ");
String userInput = scanner.nextLine();
char[] chars = userInput.toCharArray();
String str = "";
for (int i = 0; i < chars.length; i++){
for (int j = 0; j < english.length; j++){
if (english[j] == chars[i]){
str = str + morse[j] + " ";
}
}
}
System.out.println(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment