I am trying to create a program the checks the frequency of letters in a string but when i run the program it doesn't work right? Any suggestions for how i can fix this?
import java.util.*;
public class LetterFreq{
public static void main(String[] args){
String[] lines = new String[50];
Scanner scan = new Scanner(System.in);
int pos = 0;
String t = " ";
//Gets the text used
System.out.print("Type text here: ");
String wal = scan.next().trim();
char [] c = wal.toCharArray();
for(int i=0;i<c.length;i++)
for(int j=i+1;j<c.length;j++)
if(c[i] == c[j]) c[j] = '-';
for(int i=0;i<c.length;i++){
if(c[i]!='-'){
pos++;
t+=String.valueOf(c[i]);
}
}
int f[] = new int[pos];
for(int i=0;i<t.length();i++){
for(int j=0;j<c.length;j++){
System.out.println(c[j]+" "+t.charAt(i));
if(wal.charAt(j)==t.charAt(i)) f[i]++;
}
}
//prints the results
for(int i=0;i<t.length();i++)
System.out.println(t.charAt(i)+" "+f[i]);
}
}