Advertisement
Kushtrim

PatternMatching

Jun 5th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import javax.swing.*;
  2. /**
  3.  * Write a description of class PatternMatching here.
  4.  *
  5.  * @author (your name)
  6.  * @version (a version number or a date)
  7.  */
  8. public class PatternMatching
  9. {
  10.     public static void main (String[] args )
  11.     {
  12.         String s  = JOptionPane.showInputDialog("Shkruani fjalen fillestare : ");
  13.         String p  = JOptionPane.showInputDialog("Shkruani mostren qe do te kerkohet");
  14.         int gjatesiaP = p.length();
  15.         int index = -1;
  16.  
  17.         if ( gjatesiaP > s.length() )
  18.         {
  19.             JOptionPane.showMessageDialog(null,"Gjatesia e mostres eshte me e madhe se fjala fillestare");
  20.             //  System.exit(0); // fuck it, exit :P
  21.         }
  22.         else
  23.         {
  24.             for ( int i = 0 ;  i< s.length() - gjatesiaP +1 ; i++)
  25.             {
  26.                 String sub =  s.substring(i,i+gjatesiaP);
  27.                 System.out.println(s);
  28.                 String hapesira = "";
  29.                 for ( int j=0 ; j<i ; j++)
  30.                 {
  31.                     hapesira += " ";
  32.                 }
  33.                 System.out.println(hapesira + sub);
  34.                 if ( p.equals(sub) )
  35.                 {
  36.                     index = i;
  37.                     break; // sepse u gjet
  38.                 }
  39.             }
  40.            
  41.         }
  42.        JOptionPane.showMessageDialog(null,"Pozita : " + (index));
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement