George
2015-10-07 21:36:44 UTC
import java.io.*;
public class Lab01
{
File inFile;
static int [] frequency = new int [256];
public Lab01()
{
for (int i=0; i < 256; i++)
frequency[i] = 0;
}
public void FileReader(String file) throws IOException
{
inFile = new File(file);
BufferedReader reader = new BufferedReader(new FileReader(inFile));
String sline = null;
while ((sline=reader.readLine()) != null)
{
int lengthOfLine = sline.length();
for (int i=0; i < lengthOfLine; i++)
{
char a = sline.charAt(i);
int index = (int)a;
frequency[index]++;
}
}
reader.close();
}
public static void main (String[] args)
{
System.out.println("Here is the Frequency of the characters from the ASCII table taken from the file:");
try
{
Lab01 bob = new Lab01();
bob.FileReader("Speech.txt");
for (int a = 48; a < 58; a++)
{
System.out.println(a-48+" : "+frequency[a]);
}
for (int b = 65; b < 91; b++ )
{
char z = (char)b;
System.out.println(z + " : "+ frequency[b]);
}
for (int c = 97; c < 123; c++)
{
char x = (char)c;
System.out.println(x + " : " + frequency[c]);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}