java - Comparing charAt(x) to String array = letter [y] -
i trying write piece of code produces letter frequency using arrays. getting bit stuck on how compare letter in string letter in array. basic pseudo code follows.
import java.util.scanner; public class test { public static void main (string[]args){ scanner sc = new scanner (system.in); system.out.print ("please enter sentence: "); string str = sc.nextline(); string [] let = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; float [] freq = new float [25]; int x,a = 0,b = 0, strcount = 0; string str1; str1 = str.replaceall(" ", ""); (x = 0; x < str1.length(); x++) { strcount++; } system.out.println("the number of characters in string :" + strcount); system.out.println();
and i'm stuck on how compare str1 let array. have tried following has problem comparing.
while (b < strcount) { while (a < let.length) { if (let[a] == str1.charat(b)) { freq[a] = freq[a]++ ; } if(let[a] != str1.charat(b)) { = a++; } } b = b++; }
any appreciated.
thank you.
well, see number of other issues 1 you're asking simple enough.
if (let[a].charat(0) == str1.charat(b)) // <-- 1 letter { freq[a]++ ; } else { a++; }
also, strcount = str1.length();
no need loop.
Comments
Post a Comment