Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ejer2 {
- public static void patron(int a1[], int a2[]){
- int aux=0; //cada vez que coincida el orden de los arreglos, aumentará en 1, si uno solo no coincide, queda en cero
- if(a1.length>=a2.length){
- for (int i = 0; i < a1.length; i++) {
- if(a1[i]==a2[aux]){
- aux++; //Esta variable aumenta para que si llega al numero total del largo del a2, significa que ahí hay un patrón idéntico
- //Por lo tanto, podrás transformar en 0
- }else aux=0;
- if(aux==a2.length){
- for (int j = i; j > i-aux; j--) {
- a1[j]=0;
- }
- aux=0;
- }
- }
- }
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int a[]={6,7,7,7,8,6,6,6,9};
- int b[]={1,2,3};
- patron(a,b);
- for (int i = 0; i < a.length; i++) {
- if(i<a.length-1) System.out.print(a[i]+"-");
- else System.out.println(a[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement