public class CountCharactersFromFile {
public static void main(String[] args) throws Exception {
FileInputStream fstream = new FileInputStream(
"C:\\Myjavacafe\\data.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
String strLine = "";
String str = "";
while ((strLine = br.readLine()) != null) {
str += strLine;
}
while ((strLine = br.readLine()) != null) {
str += strLine;
boolean ifFlag = false;
while ((str = br.readLine()) != null) {
String[] st = str.split(" ");
System.out.println("st.toString():"+st.toString());
System.out.println("strLine: "+strLine);
if(strLine.equals(st.toString())){
ifFlag = true;
System.out.println("Flag: "+ifFlag);
}
}
}
String st = str.replaceAll(" ", "");
char[] third = st.toCharArray();
System.out.println("Character Total");
for (int counter = 0; counter < third.length; counter++) {
char ch = third[counter];
int count = 0;
for (int i = 0; i < third.length; i++) {
if (ch == third[i])
count++;
}
boolean flag = false;
for (int j = counter - 1; j >= 0; j--) {
if (ch == third[j])
flag = true;
}
if (!flag) {
System.out.println(ch + " " + count);
}
}
}
}
Build Your Own Test Framework
-
[image: Build Your Own Test Framework]
Learn to write better automated tests that will dramatically increase your
productivity and have fun while doing so...
32 minutes ago
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.