Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. package alphabetcounter;
  2. import java.util.*;
  3.  
  4. /**
  5. *
  6. * @author Mikoi
  7. */
  8. public class AlphabetCounter {
  9. public static void main(String[] args) {
  10. Scanner userInput = new Scanner(System.in);
  11.  
  12. System.out.println("Please input a paragraph.");
  13. String userParagraph = userInput.next();
  14.  
  15. char[] splitParagraph = userParagraph.toCharArray();
  16. char[] lowerAlphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
  17. char[] upperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
  18. int[] alphabetCounter = new int[26];
  19.  
  20. for(int i = 0; i < splitParagraph.length; i++) { //all loops until the whole paragraph is read
  21. for(int j = 0; i != lowerAlphabet.length; j++) { //loops until condition is found
  22. if((splitParagraph[i] == lowerAlphabet[j]) || (splitParagraph[i] == upperAlphabet[j])) {
  23. alphabetCounter[j]++;
  24. }
  25. }
  26. }
  27.  
  28. System.out.println("Alphabets:" + "\t Frequency" + "\n"
  29. +"A/a: " + "\t" +alphabetCounter[0] + "\n"
  30. +"B/b: " + "\t" +alphabetCounter[1] + "\n"
  31. +"C/c: " + "\t" +alphabetCounter[2] + "\n"
  32. +"D/d: " + "\t" +alphabetCounter[3] + "\n"
  33. +"E/e: " + "\t" +alphabetCounter[4] + "\n"
  34. +"F/f: " + "\t" +alphabetCounter[5] + "\n"
  35. +"G/g: " + "\t" +alphabetCounter[6] + "\n"
  36. +"H/h: " + "\t" +alphabetCounter[7] + "\n"
  37. +"I/i: " + "\t" +alphabetCounter[8] + "\n"
  38. +"J/j: " + "\t" +alphabetCounter[9] + "\n"
  39. +"K/k: " + "\t" +alphabetCounter[10] + "\n"
  40. +"L/l: " + "\t" +alphabetCounter[11] + "\n"
  41. +"M/m: " + "\t" +alphabetCounter[12] + "\n"
  42. +"N/n: " + "\t" +alphabetCounter[13] + "\n"
  43. +"O/o: " + "\t" +alphabetCounter[14] + "\n"
  44. +"P/p: " + "\t" +alphabetCounter[15] + "\n"
  45. +"Q/q: " + "\t" +alphabetCounter[16] + "\n"
  46. +"R/r: " + "\t" +alphabetCounter[17] + "\n"
  47. +"S/s: " + "\t" +alphabetCounter[18] + "\n"
  48. +"T/t: " + "\t" +alphabetCounter[19] + "\n"
  49. +"U/u: " + "\t" +alphabetCounter[20] + "\n"
  50. +"V/v: " + "\t" +alphabetCounter[21] + "\n"
  51. +"W/w: " + "\t" +alphabetCounter[22] + "\n"
  52. +"X/x: " + "\t" +alphabetCounter[23] + "\n"
  53. +"Y/y: " + "\t" +alphabetCounter[24] + "\n"
  54. +"Z/z: " + "\t" +alphabetCounter[25]);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement