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 fjala = JOptionPane.showInputDialog("Shkruani fjalen fillestare : ");
- String mostra = JOptionPane.showInputDialog("Shkruani mostren qe do te kerkohet");
- int gjatesiaEMostres = mostra.length();
- int index = -1;
- if ( gjatesiaEMostres > fjala.length() )
- {
- JOptionPane.showMessageDialog(null,"Gjatesia e mostres eshte me e madhe se fjala fillestare");
- // System.exit(0);
- }
- else
- {
- String hapesira = "";
- for ( int i = 0 ; i<= fjala.length() - gjatesiaEMostres; i++)
- {
- String sub = fjala.substring(i,i+gjatesiaEMostres).toUpperCase();
- // po e konvertojme ne fun mostren dhe fjaline ne shkronja te medhaja, ne menyre qe algoritmi per gjetjen e pozites se mostres ne fjali te mos jetë case-sensitive
- if ( mostra.toUpperCase().equals(sub))
- {
- index = i;
- // tash e printojme edhe fjaline, se bashku me mostren, nen te ne poziten ku eshte gjetur
- System.out.println(fjala);
- System.out.println(hapesira + mostra);
- break; // sepse u gjet
- }
- else {
- hapesira += " ";
- }
- }
- JOptionPane.showMessageDialog(null,"Pozita : " + (index));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement