class Com_pare
{
public static void main(String args[])
{
int i=0,m,t,n,o,c=0;
String search="six";
String s1="welcomlce to jalcva";
String s2="six pack is alwas six in the interval of six";
String p;
String x;
char a[]=s2.toCharArray();
for(i=0;i<a.length;i++)
{
if(a[i]=='s' && a[i+1]=='i' && a[i+2]=='x')
{
c=c+1;
}
}
for(t=0;t<c;t++)
{
m=s2.indexOf("six");
s2=s2.substring(0,m)+"was"+s2.substring(m+search.length(),s2.length());
}
System.out.println(" String After replacement "+s2);
System.out.println(" no. of timelc occurs "+c);
}
}
{
public static void main(String args[])
{
int i=0,m,t,n,o,c=0;
String search="six";
String s1="welcomlce to jalcva";
String s2="six pack is alwas six in the interval of six";
String p;
String x;
char a[]=s2.toCharArray();
for(i=0;i<a.length;i++)
{
if(a[i]=='s' && a[i+1]=='i' && a[i+2]=='x')
{
c=c+1;
}
}
for(t=0;t<c;t++)
{
m=s2.indexOf("six");
s2=s2.substring(0,m)+"was"+s2.substring(m+search.length(),s2.length());
}
System.out.println(" String After replacement "+s2);
System.out.println(" no. of timelc occurs "+c);
}
}
No comments:
Post a Comment