Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.ArrayList;
- import java.util.HashMap;
- class Morse {
- public HashMap<String, String> morseMap = new HashMap<String, String>();
- public Morse() {
- morseMap.put("-.-.--", "!");
- morseMap.put("....-", "4");
- morseMap.put("..--..", "?");
- morseMap.put("--..--", ");");
- morseMap.put(".-.-.-", ".");
- morseMap.put("..---", "2");
- morseMap.put("...--", "3");
- morseMap.put("--...", "7");
- morseMap.put("-....", "6");
- morseMap.put(".....", "5");
- morseMap.put("---..", "8");
- morseMap.put("-...", "B");
- morseMap.put("----.", "9");
- morseMap.put(".--.", "P");
- morseMap.put("-----", "0");
- morseMap.put("--..", "Z");
- morseMap.put("-.--", "Y");
- morseMap.put("-..-", "X");
- morseMap.put("-.-.", "C");
- morseMap.put("...-", "V");
- morseMap.put(".----", "1");
- morseMap.put("..-.", "F");
- morseMap.put("....", "H");
- morseMap.put(".---", "J");
- morseMap.put("--.-", "Q");
- morseMap.put("-..-.", "/");
- morseMap.put(".-..", "L");
- morseMap.put("...", "S");
- morseMap.put("---", "O");
- morseMap.put("-.-", "K");
- morseMap.put(".-.", "R");
- morseMap.put("..-", "U");
- morseMap.put("-..", "D");
- morseMap.put(".--", "W");
- morseMap.put("--.", "G");
- morseMap.put("-.", "N");
- morseMap.put("--", "M");
- morseMap.put("..", "I");
- morseMap.put(".-", "A");
- morseMap.put("-", "T");
- morseMap.put(".", "E");
- }
- // Votre code ici
- public String convert(String input){
- String motDuMessage = null;
- String message=null;
- String chaine = input;
- String[] chaineDecoupeParMot = chaine.split(" ");
- message="";
- for(int i = 0; i<(chaineDecoupeParMot.length); i++) {
- if (i==0)
- {
- motDuMessage = "";
- }
- else {
- motDuMessage = " ";
- }
- String[] chaineDecoupeParLettre = chaineDecoupeParMot[i].split(" ");
- String motEnCours=chaineDecoupeParLettre[i];
- for (int j = 0; j < ((motEnCours.length())+1); j++) {
- String actualLettre = (chaineDecoupeParLettre[j]);
- String morseCar = morseMap.get(actualLettre).toString();
- motDuMessage += morseCar;
- }
- message =message + motDuMessage;
- }
- System.out.println(message);
- return message;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement