-5

My code:

import java.io.*;
public class ProgramSix {

    public int count(String fileName, char charToSerach) throws FileNotFoundException, IOException {

        char lower = Character.toLowerCase(charToSerach);
        char upper = Character.toUpperCase(charToSerach);

        int count = 0;

        try (BufferedReader reader = new BufferedReader(new FileReader("xanadu.txt"))) {
            int ch = 0;
            while ((ch = reader.read()) != -1) {
                if (lower == ch || upper == ch) {
                    count++;
                }
            }
        }
        System.out.println("The character '" + charToSerach + "' appears: " + count + " times in the .txt file");
        return count;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Program6 program6 = new Program6();

            String fileName = "xanadu";
            int numAs = programSix.count(fileName, 'a');
            int numBs = programSix.count(fileName, 'b');
            int numCs = programSix.count(fileName, 'c');

        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}

So now my code properly gives the output: giving the number of times the characters 'a' 'b' and 'c' appeared in my .txt file. Now what is the best way to read the same .txt file and give out three different letters in a output.txt file and the number of times they occurred?

New2AllThis
  • 3
  • 1
  • 6

1 Answers1

-1

You are using the wrong class

see

class  ProgramSix 

vs

Program6 program6 = new Program6();
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64