Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.92 KB | None | 0 0
  1.  
  2. public class Ejer2 {
  3.  
  4.     public static void patron(int a1[], int a2[]){
  5.         int aux=0; //cada vez que coincida el orden de los arreglos, aumentará en 1, si uno solo no coincide, queda en cero
  6.        
  7.         if(a1.length>=a2.length){
  8.             for (int i = 0; i < a1.length; i++) {
  9.                 if(a1[i]==a2[aux]){
  10.                     aux++; //Esta variable aumenta para que si llega al numero total del largo del a2, significa que ahí hay un patrón idéntico
  11.                         //Por lo tanto, podrás transformar en 0
  12.                    
  13.                 }else aux=0;
  14.                
  15.                 if(aux==a2.length){
  16.                     for (int j = i; j > i-aux; j--) {
  17.                         a1[j]=0;
  18.                     }
  19.                     aux=0;
  20.                 }
  21.             }
  22.         }
  23.        
  24.     }
  25.    
  26.     public static void main(String[] args) {
  27.         // TODO Auto-generated method stub
  28.  
  29.         int a[]={6,7,7,7,8,6,6,6,9};
  30.         int b[]={1,2,3};
  31.        
  32.         patron(a,b);
  33.        
  34.         for (int i = 0; i < a.length; i++) {
  35.             if(i<a.length-1)    System.out.print(a[i]+"-");
  36.             else System.out.println(a[i]);
  37.            
  38.         }
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement