Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Mirror {
- /**
- * mirror(s) retourne la chaîne de caractères
- * s à l'envers
- *
- * @param s
- * La chaîne à inverser
- */
- public static String mirror(String s) {
- String ans = "";
- int len = getStringLength(s);
- /// Dojo:Q1 [NE PAS MODIFIER CETTE LIGNE]
- // Ecrire ici la reponse à Q1
- int n = 0 ;
- String mir = "" ;
- n = getStringLength (s) ;
- for (int i = n-1 ; i<1 ; i-- ){
- mir = mir + stringCharAt(s, i) ;
- }
- return mir ;
- /// Dojo:End [NE PAS MODIFIER CETTE LIGNE]
- return ans;
- }
- /**
- * Renvoie une chaîne d'un caractère: celui de {@code str} à la position
- * {@code idx}.
- *
- * @param str la chaîne d'où extraire le caratère.
- * @param idx l'index dans la chaîne.
- * @return le caractère dans {@code str} à l'indice {@code idx}, ou la chaîne
- * vide si l'indice est invalide.
- */
- public static String stringCharAt(String str, int idx) {
- if (idx < 0 || str.length() < idx) {
- return "";
- } else {
- return String.valueOf(str.charAt(idx));
- }
- }
- /**
- * Calcule la longueur d'une chaîne de caractères
- * @param t La chaîne dont on veut connaître la longueur
- * @return La longueur de la chaîne
- */
- public static int getStringLength(String s) {
- return s.length();
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement