Advertisement
Adumb_Copper

Assessment1

Jan 12th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. //lolwut
  2.  
  3. public int findString(String str, int start)
  4. {
  5.     int notGood = 0;
  6.     for (int i = start; i < line.length(); i++)
  7.     {
  8.         if (line.substring(i , i + 1).equals(str))
  9.         {
  10.             if (i == line.length() - 1 && notGood == 0)
  11.                 return i;
  12.             else if (i == line.length() - 1)
  13.                 return -1;
  14.             if (line.substring(i + 1 , i + 2).equals(str) && notGood == 0)
  15.                 return i;
  16.             else
  17.                 notGood = 1;
  18.         }
  19.         else
  20.             notGood = 0;
  21.     }
  22.     return -1;
  23. }
  24.  
  25.  
  26. private int countString(String str)
  27. {
  28.     int counter = 0;
  29.     int psn = 0;
  30.  
  31.     while (psn >= 0)
  32.     {
  33.         psn = line.indexOf(str , psn);
  34.         if (psn >= 0)
  35.         {
  36.             psn++;
  37.             counter++;
  38.         }
  39.     }
  40.     return counter;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement