Advertisement
Guest User

27/05

a guest
May 27th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. public class Array {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         System.out.println(busca("b"));
  6.  
  7.     }
  8.  
  9.     static int busca(String nome) {
  10.  
  11.         List<Integer> _lista = new ArrayList<>();
  12.  
  13.         String lista[] = new String[5];
  14.         lista[0] = "aaa";
  15.         lista[1] = "bbb";
  16.         lista[2] = "ccc";
  17.         lista[3] = "ddd";
  18.         lista[4] = "eee";
  19.  
  20.         for (int i = 0; i < 4; i++) {
  21.  
  22.             if (lista[i].equals(nome)) {
  23.  
  24.                 System.out.println(i);
  25.                 _lista.add(i);
  26.  
  27.             }
  28.         }
  29.  
  30.         if (_lista.isEmpty()) {
  31.             return -1;
  32.         }
  33.  
  34.         return 0;
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement