Using java program we are going to find the repeating charater in the given string.If there is more than one string then print first one.
Program in Java:
import java.util.*;
public class Main{
public static void main(String args[])
{
String s;
Scanner sc=new Scanner(System.in);
s=sc.next();
int n,i,j,k=0;
n=s.length();
char c=' ';
for(i=0;i<n;i++)
{
int count=0;
for(j=0;j<n;j++)
{
if(s.charAt(i)==s.charAt(j))
{
count++;
}
}
if(count>k)
{
k=count;
c=s.charAt(i);
}
}
for(i=0;i<k;i++)
{
System.out.println(c+"");
}
}
}
Post a Comment