Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int[] frequentie(String zin)
- {
- int[] frequentie = new int[37];
- for(int i = 0; i < zin.length(); i++)
- {
- char c = zin.charAt(i);
- if(c >= 'a' && c <= 'z')
- frequentie[c-97] = frequentie[c-97] + 1;
- else if(c > '0' && c <= '9')
- frequentie[c-22] = frequentie[c-22] + 1;
- else if(c == ' ')
- frequentie[c+4] = frequentie[c+4] + 1;
- }
- System.out.println("--------------------------------------------------------------------------");
- System.out.println("Ter controle de frequenties van alle karakters: ");
- System.out.println(" ");
- float max = frequentie[0];
- float stapgrootte = 0;
- float sterretjes = 0;
- for(int i = 0; i < frequentie.length; i++)
- {
- System.out.print(frequentie[i] + " ");
- if(frequentie[i] > max)
- max = frequentie[i];
- }
- if(max <= 10)
- stapgrootte = 1;
- else if(max > 10)
- stapgrootte = max/10;
- for(int i = 0; i < frequentie.length; i++)
- {
- sterretjes = frequentie[i]/stapgrootte;
- if(sterretjes == 1.0)
- System.out.println(" * ");
- }
- System.out.println("");
- System.out.println("a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 ");
- System.out.println(" ");
- System.out.println("De max is " + max + " en de stappgrootte is " + stapgrootte);
- System.out.println("--------------------------------------------------------------------------");
- return frequentie;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement