So here's the code I've got so far...
import java.util.Scanner;
class count{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
System.out.println("Enter a string");
String sent=s.nextLine();
int len = sent.length();
int arr[]=new int[len];
int count=1;
char ch[] = new char[len];
for(int i = 0; i <= len-1; i ++)
{
ch[i] = sent.charAt(i);
}
for(int j= 0;j<=len-1;j++){
for(int k=0;k<=len-1;k++){
if(ch[j]==ch[k]){
arr[j]= count++;
}
}
}
int max=arr[0];
for(int z=1;z<=len-1;z++){
if(count>max)
max=count;
}
System.out.println(max);
System.out.println("The character that appears the most number of times is " +arr[max]);
}
}
I get count to display the number of times each character appears in the string, I'm not able to compare it with the rest of the elements in the array.
The number of appearances is stored in array 'arr[]' how do I find the largest integer in this array? And Also, how do I display the character that has appeared the maximum number of times?
The logic of the code isn't working after,
int max=arr[0];
Any ideas as to what to do?