Fakedo0r

Contador de Secuencias LA

Mar 17th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. public static void main(String[] args)
  2. {
  3.     System.out.println(ContadorSecuencias(" ALALAFLEAsLA   ALA como La jaja ALA"));
  4. }
  5.  
  6. public static String ContadorSecuencias(String sCadena)
  7. {
  8.     int         index;
  9.     int         iContWord;
  10.     int         iContSec;
  11.     boolean     bSecExiste;
  12.  
  13.     iContWord = 0;
  14.     iContSec = 0;
  15.    
  16.     bSecExiste = false;
  17.  
  18.     for (index = 0; index < sCadena.length(); index ++)
  19.     {
  20.         if (index == 0 && sCadena.charAt(index) == 'A')
  21.         {
  22.             while (index < sCadena.length() && sCadena.charAt(index) != ' ')
  23.             {
  24.                 if (sCadena.charAt(index) == 'L' && sCadena.charAt(index + 1) == 'A')
  25.                 {
  26.                     iContSec ++;
  27.                    
  28.                     bSecExiste = true; 
  29.                 }
  30.                
  31.                 index ++;
  32.             }
  33.            
  34.             if (bSecExiste = true) iContWord = 1; bSecExiste = false;
  35.         }
  36.         else
  37.         {
  38.             if (sCadena.charAt(index) == 'A' && sCadena.charAt(index - 1) == ' ')
  39.             {  
  40.                 while (index < sCadena.length() && sCadena.charAt(index) != ' ')
  41.                 {
  42.                     if (sCadena.charAt(index) == 'L' && sCadena.charAt(index + 1) == 'A')
  43.                     {
  44.                         iContSec ++;
  45.                        
  46.                         bSecExiste = true;
  47.                     }
  48.                    
  49.                     index ++;
  50.                 }
  51.  
  52.                 if (bSecExiste = true) iContWord ++; bSecExiste = false;
  53.             }      
  54.         }
  55.     }
  56.  
  57.     return ("Existe " + iContWord + " palabra(s)\n") +
  58.            ("Existe " + iContSec + " secuencia(s)");   
  59. }
Advertisement
Add Comment
Please, Sign In to add comment