Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 9th, 2013  |  syntax: None  |  size: 0.84 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Ex13_5
  2. {
  3.     private String main;
  4.     private String smaller;
  5.     public Ex13_5(String main)
  6.     {
  7.         this.main=main;
  8.         smaller = main;
  9.     }
  10.  
  11.     public boolean find(String t)
  12.     {
  13.         if(main.length() < t.length())
  14.             return false;
  15.         else if(main.substring(0, t.length()).equals(t))
  16.             return true;
  17.         else
  18.         {
  19.             main = main.substring(1);
  20.             return find(t);
  21.         }
  22.  
  23.     }
  24.  
  25.     public int indexOf(String s)
  26.     {
  27.         if(!find(s))
  28.         return -1;
  29.         else
  30.         {
  31.             if(smaller.substring(0, s.length()).equals(s))
  32.                 return 1;
  33.             else
  34.             {
  35.                 smaller = smaller.substring(1);
  36.                 return 1+ indexOf(s);
  37.             }
  38.         }
  39.        
  40.        
  41.  
  42.     }
  43.  
  44. }