Hi friends,
I am trying to find the Count continuous repeated occurrence of string in string array.
(eg)
input: now now how cow how
output: now---->2
but i d't know what is wrong in my code,so please any one help me to find the soluction..
public class Stringmaxrepeate {
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String[] s=new String[10];
int count=1;
Map <String,Integer> h = new HashMap<String,Integer>();
System.out.println("enter the 10 String to find the Max Strint Repeate");
for(int i=0;i<5;i++)
{
s[i]=in.nextLine();
}
for(int j=1;j<5;j++)
{
if (s[j]==s[j-1])
{
count++;
}
else {
if (count > 1) {
h.put( s[j],count );
count=0;
}
}
count = 1;
}
System.out.println(h);
int max = Collections.max(h.values());
System.out.println(max);
}
}