Shavit

P. 110 Ex. 11.25

Mar 1st, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. // Shavit Borisov
  2. // HW
  3.  
  4. public class PhoneBook
  5. {
  6.     final int SIZE = 10; // can be changed
  7.     String[] names = new String[SIZE];
  8.    
  9.     public String[] search(String input)
  10.     {
  11.         String[] results = new String[SIZE];
  12.         boolean equal;
  13.         int nextIni = 0;
  14.         for(int i = 0; i < SIZE; i++)
  15.         {
  16.             equal = true;
  17.             for(int j = 0; j < input.length() && equal; j++)
  18.             {
  19.                 if(input.charAt(j) != names[i].charAt(j))
  20.                     equal = false;
  21.             }
  22.             if(equal)
  23.             {
  24.                 results[nextIni] = names[i];
  25.                 nextIni++;
  26.             }
  27.         }
  28.         return results;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment