Sunday, March 18, 2018

WAP to print char occurrence in given string I/P : s=anand s2=prabhakar O/P : 3a 0n a n 0d

/*
WAP to print char occurrence in given string
I/P : s=anand
  s2=prabhakar

O/P : 3a 0n a n 0d
*/

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

public static void main(String[] args) {
String s="anand";
String s2="prabhakar";
String s3="";
for(int i=0;i<s.length();i++)
{
String ch=String.valueOf(s.charAt(i));
Pattern p=Pattern.compile(ch);
Matcher m=p.matcher(s2);
int count=0;;
while(m.find())
{
count++;
}
if(s3.contains(ch))
System.out.print(ch+"  ");
else
System.out.print(count+ch+"  ");
s3=s3+ch;
}

}

}

Share this

0 Comment to "WAP to print char occurrence in given string I/P : s=anand s2=prabhakar O/P : 3a 0n a n 0d"

Post a Comment