iPad 738 AM Write a program that reads a text file and count
Solution
 import java.io.DataInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.Scanner;
public class MyMain {
   public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        int counter = 0;
        DataInputStream dis = new DataInputStream(System.in);
        System.out.println(\"input absolute file name with path\");
        File file = new File(dis.readLine());
        Scanner scanner = new Scanner(file);
        UseCount[] useCount = new UseCount[10000];
        while (scanner.hasNext()) {
            String temp = scanner.next();
            Boolean flag = false;
            UseCount use = new UseCount(temp);
            int i = 0;
            for (i = 0; i < counter && i < 10000; i++) {
                if (useCount[i].word.equals(use.word)) {
                    useCount[i].count = useCount[i].count + 1;
                    flag = true;
                    break;
                }
            }
            if (flag == false) {
                useCount[counter++] = new UseCount(temp);
                // System.out.println(use.word);
            }
       }
        Arrays.sort(useCount, 0, counter);
        System.out.println(\"Strings after sorting in descending order\");
        for (int i = 0; i <= 25 && i < counter; i++) {
            System.out.println(useCount[i].word + \"\\t\" + useCount[i].count);
        }
        scanner.close();
    }
}
class UseCount implements Comparable<UseCount> {
   String word;
    int count;
   public UseCount(String word) {
        this.word = word;
        count = 1;
    }
   @Override
    public int compareTo(UseCount other) {
        return other.count - this.count;
   }
 }


