Exercice en java

delgado -  
daronmaster Messages postés 326 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

j ai un pti cours enjava et je galere, il y a un exercice ou par exemple on rentre le "mot" suivant aaaaccbbbddddddefffff et on doit obtenir abcdef

merci de m aider
Configuration: Windows XP
Internet Explorer 6.0

2 réponses

  1. guilom076 Messages postés 52 Statut Membre 2
     
    Oula, sa fait très longtemps que j'ai pas fait de java..
    Moi je ferais sa :

    string chaine;
    char car;
    string rep;

    car = 'a';
    while(car <= z)
    {
    if (chaine.indexOf(car)!= null)
    {
    rep=rep+car;
    }
    car = car+1;
    }

    Bon je suis sur que ce n'est syntaxiquement pas bon mais sa doit te donner une piste pour ton exo..
    0
  2. daronmaster Messages postés 326 Date d'inscription   Statut Membre Dernière intervention   44
     
    moi j'aurais fait un truc du genre

    char c;

    string ta_string="aaaabbbbbccccddddeeefff";

    string res=string(ta_string.charAt(0));

    int i=0; // ou 1 je ne sais plus comment sont indexés les string ...
    while(i<(ta_string.length()-1)){

    if (=ta_string.charAt(i) != ta_string.charAt(i+1)){

    res.concat(string(ta_string.charAt(i+1)));
    }

    i++;
    }

    essaie voir

    tchû
    0