Paste2 Logo
  1. /*
  2. Esercizio sulle stringhe
  3. Autore: Red Skull 92
  4. Mail: RedSkull92[AT]gmail[DOT]com
  5. Web: http://redskull92.wordpress.com
  6. */
  7. class Stringhe
  8. {
  9.      public static void main(String args[])
  10.      {
  11.          Stringhe a = new Stringhe();
  12.          a.rmDoppie("cciiaaoo");
  13.      }
  14.      
  15.      public void rmDoppie(String str)
  16.      {
  17.         int i,conto=0,pos=0;
  18.         String nuova="",removed="";
  19.        
  20.         for(i=0;i<str.length();i++)
  21.         {
  22.             if(i != str.length() -1 && str.charAt(i)==str.charAt(i+1))
  23.             {
  24.                 removed+=str.charAt(i);
  25.                 conto++;
  26.             }
  27.             else
  28.             {
  29.                 nuova+=str.charAt(i);
  30.             }
  31.         }
  32.        
  33.         System.out.println("Stringa Completa: "+str);
  34.         System.out.println("Stringa Modificata: "+nuova);
  35.         System.out.println("Lettere Tolte: "+removed);
  36.         System.out.println("Numero Di Lettere Tolte: "+conto);
  37.      }
  38. }
  39.  

Data una stringa qualsiasi, vengano eliminate tutte le doppie consecutive e vengano restituiti/printati