Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /**
  8.  *
  9.  * @author stud-b11704
  10.  */
  11. public class Sub
  12. {
  13.     public boolean findSub(String text, String sText)
  14.     {
  15.         for(int i = 0; i < text.length(); i++)
  16.         {
  17.             for(int i2 = 0; i2 < sText.length(); i2++)
  18.             {  
  19.                 if(i == text.length()-1)
  20.                 {
  21.                     return false;
  22.                 }
  23.                 if(sText.charAt(i2) == text.charAt(i))
  24.                 {
  25.                     i++;
  26.                     if(i2 == sText.length()-1)
  27.                     {
  28.                         System.out.println(i - sText.length());
  29.                         return true;
  30.                     }
  31.                 }
  32.                 else
  33.                 {
  34.                     break;
  35.                 }
  36.             }
  37.         }
  38.         return false;
  39.     }
  40. }
  41.  
  42. /*
  43.  * To change this license header, choose License Headers in Project Properties.
  44.  * To change this template file, choose Tools | Templates
  45.  * and open the template in the editor.
  46.  */
  47.  
  48. /**
  49.  *
  50.  * @author stud-b11704
  51.  */
  52. public class Start
  53. {
  54.     public static void main(String args[])
  55.     {
  56.         Sub s = new Sub();
  57.         System.out.println(s.findSub("Ala ma kota", "tama"));
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement