/*
Write a Java Program to print char occurrence in given string
I/P : aabbccadc
O/P : 3a 2b 3c 1d
*/
import java.util.regex.*;
public class Test
{
public static void main(String[] args)
{
String s="aabbccadc";
String s4="";
for(int i=0;i<s.length();i++)
{
String ch=String.valueOf(s.charAt(i));
if(!(s4.contains(ch)))
{
Pattern p=Pattern.compile(ch);
Matcher m=p.matcher(s);
int count=0;String s3=null;
while(m.find())
{
count++;
s3=m.group();
s4=s4.concat(s3);
}
System.out.print(count+s3+" ");
}
}
}
}
Write a Java Program to print char occurrence in given string
I/P : aabbccadc
O/P : 3a 2b 3c 1d
*/
import java.util.regex.*;
public class Test
{
public static void main(String[] args)
{
String s="aabbccadc";
String s4="";
for(int i=0;i<s.length();i++)
{
String ch=String.valueOf(s.charAt(i));
if(!(s4.contains(ch)))
{
Pattern p=Pattern.compile(ch);
Matcher m=p.matcher(s);
int count=0;String s3=null;
while(m.find())
{
count++;
s3=m.group();
s4=s4.concat(s3);
}
System.out.print(count+s3+" ");
}
}
}
}
0 Comment to "Write a Java Program to print char occurrence in given string I/P : aabbccadc O/P : 3a 2b 3c 1d"
Post a Comment