-
SUBSTRING
import javax.swing.*;
public class Substring{
public static void main (String a[]){
String m = JOptionPane.showInputDialog("Enter a String:");
String sub = JOptionPane.showInputDialog("Enter a Substring:");
String temp = "";
int num = 0;
for (int x=0;x<m.length();x++){
for (int y=0;y<sub.length();y++){
temp = temp + m.charAt(x);
}
if (temp.equalsIgnoreCase(sub)){
num++;
}
temp="";
}
JOptionPane.showMessageDialog(null,"Number of occurence of substring" + sub + " in string" + m + "is" + num);
}
}:-h:-h
-
Re: SUBSTRING