Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- /**
- * Write a description of class PatternMatching here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PatternMatching
- {
- public static void main (String[] args )
- {
- String s = JOptionPane.showInputDialog("Shkruani fjalen fillestare : ");
- String p = JOptionPane.showInputDialog("Shkruani mostren qe do te kerkohet");
- int gjatesiaP = p.length();
- int index = -1;
- if ( gjatesiaP > s.length() )
- {
- JOptionPane.showMessageDialog(null,"Gjatesia e mostres eshte me e madhe se fjala fillestare");
- // System.exit(0); // fuck it, exit :P
- }
- else
- {
- for ( int i = 0 ; i< s.length() - gjatesiaP +1 ; i++)
- {
- String sub = s.substring(i,i+gjatesiaP);
- System.out.println(s);
- String hapesira = "";
- for ( int j=0 ; j<i ; j++)
- {
- hapesira += " ";
- }
- System.out.println(hapesira + sub);
- if ( p.equals(sub) )
- {
- index = i;
- break; // sepse u gjet
- }
- }
- }
- JOptionPane.showMessageDialog(null,"Pozita : " + (index));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement