Tuesday, May 25, 2021

Write a program that takes a filename as input. The task is to count the number of alphabets in the mentioned file.

Write a program that takes a filename as input. The task is to count the number of alphabets in the mentioned file. You have to create 26 threads each thread will be responsible for the counting of a particular letter in the file. All threads will print their character count and also return the count, main thread will receive the count of each thread and print the sum which will be equivalent to no of characters in file. Character that thread has to count should be passed as input parameter to each thread.

Code given below 

import java.util.*;

import java.io..; 

public class LetterCounter ( public static void main(String args[]) throws I0Exception( Scanner keyboard = new Scanner(System.in); 

name System.out.printInrEnter the name of the text file to read:"); 

String filename = keyboard.next(); 

String alphabet = "abcdefghijklmnopqrstuvwxyz"; 

char[] array = "abcdefghijklmnopqrstuvwxyz".toCharArray(); 

Scanner fileScan = new Scanner(new File(filename)); 

    while (fileScan.hasNext()) {

      String line = fileScan.nextLine();

      line = line.toLowerCase( );

 System.outprintln("Letters - Frequencies in file:"); 


for (int i = 0:1< filename.length(); i++) {

    array[i] filename.charAt(i); 

int find = 0; 

for (int j= 0; j<= i; j++) {

 if (filename.charAt(i) == array[j]) 

{

find++; 

    }

    if (find == 1) 

System.out.println("Number of Occurrence of " + filename.charAt(i) + " is: " + filename.charAt(i)); }

fileScan.close(); 

}

}

}

• • • 



No comments:

Post a Comment