// Je ne suis qu'un débutant, c'est mon premier programme, ça fonctionne bien mais est-ce que je peux le rendre meilleur?Anglais vers le convertisseur de code Morse, comment puis-je le rendre plus efficace?
import java.util.*;
public class NewClass1 {
public static void main(String[] args) {
Character alphabet [] = {'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 morseCode [] = {".- ", "-... ", "-.-. ", "-.. ", ". ", "..-. ", "--. ", ".... ", ".. ", ".--- ", "-.- ", ".-.. ", "-- ", "-. ", "--- ", ".--. ", "--.- ", ".-. ", "... ", "- ", "..- ", "...- ", ".-- ", "-..- ", "-.-- ", "--.. ", "| "};
//putting alphabets and morsecode in HashMap
Map<Character, String> morseCodes = new HashMap<>();
for(int i = 0; i < alphabet.length; i++)
{
morseCodes.put(alphabet[i], morseCode[i]);
}
//Took user input and converted it into LowerCase Character Array
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
char[] translate = input.toLowerCase().toCharArray();
//Translating user input(translate[]) using for loop
for(int j=0; j<input.length(); j++){
System.out.print(morseCodes.get(translate[j]));
}
}
}
Vous pouvez le mettre en retrait correctement. – khelwood
Ce n'est pas vraiment un problème de programmation spécifique. –
Je crois que ce type de questions sont les bienvenues à [Revue de code] (https://codereview.stackexchange.com/) échange de pile – hrust