I typed out this program to count the number of times each character appears in a String.
import java.util.Scanner;
public class fre {
public static void main(String[] args) {
Scanner s=new Scanner (System.in);
System.out.println("Enter a string");
String sent = s.nextLine();
String str=sent.toUpperCase();
int len=str.length();
char save[]=new char[len];
for (int i=0;i<len;i++){
save[i]=str.charAt(i);
}
char a=0;
int count=0;
for(int i=0;i<len;i++){
a=save[i];
for(int j=0;j<len;j++){
if(save[j]==a)
count ++;
}
}
for(int i=0;i<len;i++)
System.out.println(save[i]+" appears "+count+" number of times");
}
}
The code is horribly wrong, can someone please guide me as to how to go about the program using simple functions and tell me what I've done wrong here?