Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class histogram
- {
- public static void main (String args[])
- {
- System.out.println("#input word");
- String word = BIO.getString();
- while (! word.equals("END"))
- {
- String wordLC = word.toLowerCase();
- int length = wordLC.length();
- int alphacount[] = new int [26];
- int highestnumber [] = new int [26];//an array to hold numbers to work out which number is highest
- for (int x = 0; x <26; x++)
- {
- alphacount[x] = letterCount(length, x, wordLC);
- highestnumber[x] = alphacount[x];
- //go to method to work out how many of each letter there are
- }
- //find which letter is most common
- int largest = 0;
- for (int v = 0; v<26; v++) //loop looks at every individual letter
- {
- if (alphacount[v] >= largest)
- {largest = alphacount[v];}
- }
- alphacount[largest] = 10;
- //print
- for (int a=10; a>0; a--)
- {
- System.out.printf("%2d", a );
- System.out.print(" | ");
- for (int j = 0; j< 26; j++)
- {
- if (alphacount[j] == a)
- {System.out.print("*");
- alphacount[j]--;
- }
- else
- {System.out.print(" ");}
- }
- System.out.println(" |");
- }
- System.out.println(" " + "+++++++++++++++++++++++++" + " ");
- System.out.println(" abcdefghijklmnopqrstuvwxyz");
- System.out.println("#input word");
- word = BIO.getString();
- }
- }
- public static int letterCount(int lengthm, int y, String wordm)
- {
- String alphabet = "abcdefghijklmnopqrstuvwxyz";
- int counter = 0;
- for (int i = 0; i<lengthm - 1; i++)
- {
- if (wordm.charAt(i) == alphabet.charAt(y))
- {
- counter++;
- }
- }
- return counter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement