Created
October 12, 2024 13:24
-
-
Save youssef3wi/ce12e03519d6ab26b39845566d8173ae to your computer and use it in GitHub Desktop.
Le javanais, aussi appelé langue de feu, est un procédé de codage argotique qui fut utilisé à la fin du 19ème siècle par certains malfaiteurs pour crypter leur conversations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * <h2>Objectif</h2> | |
| * <p> | |
| * Le javanais, aussi appelé langue de feu, est un procédé de codage argotique qui fut utilisé | |
| * à la fin du 19ème siècle par certains malfaiteurs pour crypter leur conversations. Écrivez un programme | |
| * retournant la traduction en javanais d'une phrase. | |
| * <p> | |
| * <h3>Fonctionnement</h3> | |
| * <p> | |
| * <ul> | |
| * <li>Avant chaque voyelle suivante (a, e, i, o, u), insérez la syllable parasite {@code av};</li> | |
| * <li>Sauf si la voyelle est precédée d'une autre voyelle.</li> | |
| * </ul> | |
| * <p> | |
| * <h3>Implémentation</h3> | |
| * <p> | |
| * Implémentez la méthode {@link #translate(String)} qui: | |
| * <ul> | |
| * <li>prend en entrée {@code text}, une chaine de caractères de moins de 255 caractères;</li> | |
| * <li>retourne la traduction en javanais, sous la forme d'une chaine de caractères.</li> | |
| * </ul> | |
| * Par simplification, les entrées ne contiennent que des miniscules. | |
| * <p> | |
| * <h3>Exemple</h3> | |
| * {@code text = hello, secret meeting tonight.} <br> | |
| * {@code javanais = havellavo, savecravet maveeting tavonavight.} | |
| */ | |
| public class Translate { | |
| private static final String vowelsAsStr = "aeiou"; | |
| public static String translate(String text) { | |
| StringBuilder result = new StringBuilder(); | |
| for (int idx = 0; idx < text.length(); idx++) { | |
| char current = text.charAt(idx); | |
| if (vowelsAsStr.chars().anyMatch(vowel -> vowel == current)) { | |
| // previous is a vowel? | |
| if (idx > 0) { | |
| char previous = text.charAt(idx - 1); | |
| if (vowelsAsStr.chars().anyMatch(vowel -> vowel == previous)) { | |
| result.append(current); | |
| continue; | |
| } | |
| } | |
| result.append("av"); | |
| } | |
| result.append(current); | |
| } | |
| return result.toString(); | |
| } | |
| public static void main(String[] args) { | |
| System.out.println("Input = hello, secret meeting tonight"); | |
| System.out.printf("Output = %s%n", translate("hello, secret meeting tonight")); | |
| System.out.println("----------------------"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment