Advertisement
Eduardo_Pires

BuscaLinear

Nov 24th, 2022
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | Jokes | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class BuscaLinear
  4. {
  5.     private int repete;
  6.     private ArrayList<Integer> repetidos = new ArrayList<Integer>();
  7.     private int[] array;
  8.  
  9.     public BuscaLinear(int[] array)
  10.     {
  11.         this.array = array;
  12.     }
  13.  
  14.     public ArrayList<Integer> getRepetidos()
  15.     {
  16.         return repetidos;
  17.     }
  18.  
  19.     public int getRepete() {
  20.         return repete;
  21.     }
  22.  
  23.     int buscaLinear(int numero)
  24.     {
  25.         repete = 0;
  26.         int i;
  27.         for(i = 0; i < array.length; i++)
  28.         {
  29.             if(numero == array[i])
  30.             {
  31.                 repetidos.add(repete);
  32.                 repete++;
  33.             }
  34.         }
  35.         return -1;
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement