Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. class histogram
  2. {
  3. public static void main (String args[])
  4. {
  5. System.out.println("#input word");
  6. String word = BIO.getString();
  7.  
  8. while (! word.equals("END"))
  9. {
  10. String wordLC = word.toLowerCase();
  11. int length = wordLC.length();
  12. int alphacount[] = new int [26];
  13. int highestnumber [] = new int [26];//an array to hold numbers to work out which number is highest
  14. for (int x = 0; x <26; x++)
  15. {
  16. alphacount[x] = letterCount(length, x, wordLC);
  17. highestnumber[x] = alphacount[x];
  18. //go to method to work out how many of each letter there are
  19. }
  20.  
  21. //find which letter is most common
  22.  
  23. int largest = 0;
  24. for (int v = 0; v<26; v++) //loop looks at every individual letter
  25. {
  26. if (alphacount[v] >= largest)
  27. {largest = alphacount[v];}
  28. }
  29. alphacount[largest] = 10;
  30. //print
  31. for (int a=10; a>0; a--)
  32. {
  33. System.out.printf("%2d", a );
  34. System.out.print(" | ");
  35.  
  36. for (int j = 0; j< 26; j++)
  37. {
  38.  
  39.  
  40. if (alphacount[j] == a)
  41. {System.out.print("*");
  42. alphacount[j]--;
  43. }
  44. else
  45. {System.out.print(" ");}
  46. }
  47. System.out.println(" |");
  48.  
  49. }
  50.  
  51. System.out.println(" " + "+++++++++++++++++++++++++" + " ");
  52. System.out.println(" abcdefghijklmnopqrstuvwxyz");
  53.  
  54. System.out.println("#input word");
  55. word = BIO.getString();
  56.  
  57. }
  58. }
  59.  
  60. public static int letterCount(int lengthm, int y, String wordm)
  61. {
  62. String alphabet = "abcdefghijklmnopqrstuvwxyz";
  63. int counter = 0;
  64.  
  65. for (int i = 0; i<lengthm - 1; i++)
  66. {
  67. if (wordm.charAt(i) == alphabet.charAt(y))
  68. {
  69. counter++;
  70. }
  71. }
  72. return counter;
  73. }
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement