Java help reading from a file -
i have section of code dont know with. supposed show dialog box select file , when file selected outputs results in histograph. have working except can not figure out variable need put text2.
private int[] countletters2() { // count 26 letters int[] count = new int[26]; //get contents file chooser.showopendialog(null); file f = chooser.getselectedfile(); try { filereader fr = new filereader(f); bufferedreader br = new bufferedreader(fr); string s; while((s = br.readline()) != null) { system.out.println(s); <------simply see if reader , buffer working } } catch(ioexception g) {} string text2 = ; <------------------------------------this problem //converts every letter uppercase text2 = text2.touppercase(); //count occurrence of each letter (case insensitive) (int = 0; < text2.length(); i++) { char character = text2.charat(i); if ((character >= 'a') && (character <= 'z')) { count[(int)character - 65]++; // ascii 'a' 65 } } return count; // return count array
move loop counts characgters loop print lines. like
private int[] countletters2() { // count 26 letters int[] count = new int[26]; //get contents file chooser.showopendialog(null); file f = chooser.getselectedfile(); try { filereader fr = new filereader(f); bufferedreader br = new bufferedreader(fr); string s; while((s = br.readline()) != null) { system.out.println(s); //converts every letter uppercase string text2 = s.touppercase(); //count occurrence of each letter (case insensitive) (int = 0; < text2.length(); i++) { char character = text2.charat(i); if ((character >= 'a') && (character <= 'z')) { count[(int)character - 65]++; // ascii 'a' 65 } } } } catch(ioexception g) {} return count; }
Comments
Post a Comment