All pastes #462139 Raw Edit

alphabet

public text v1 · immutable
#462139 ·published 2007-04-28 02:20 UTC
rendered paste body
import java.io.*;

public class Alphabet
{
	int[] frequency = new int[26];
    public Alphabet(String fileName)
	{
		for (int i=0; i < frequency.length; i++)
		frequency[i] = 0;

		try
		{
			RandomAccessFile raf = new RandomAccessFile(fileName, "r");
			int ch = raf.read();
			while (ch != -1)
			{
				//System.out.println((char)ch);
				char c = (char) ch;
				for (int j = 0 ; j < 26 ; j++)
				{
					if (c == ('a' + j)) frequency[j]++;
				}
				ch = raf.read();
			}
		}
		catch(FileNotFoundException ffe)
		{
			System.out.println("File not found");
		}
		catch(IOException ioe)
		{
			System.out.println("IO Exception "+ioe.getMessage());
		}

		for (int j = 0; j < 26; j++)
		{
			System.out.println((char) ('a' + j) + " * "+ frequency[j]);
		}
		/*{

			face = j + randomNumbers.nextInt(26);

			System.out.printf("%d ", face);


			for (int f = 1; f <= face; f++)
				System.out.print('*');

			System.out.println();
		}*/
	}

	
	public static void main( String args[] )
	{
		Alphabet a = new Alphabet(args[0]);
	}
       
}