Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1.  
  2. public class Sort {
  3. public static void main(String[] args) {
  4. new Sort().run();
  5. }
  6.  
  7. public void run() {
  8. int printedString = 0;
  9. String[] array = { "A", "B", "C", "D", "E", "F", "G", "H", "A", "B", "C", "D", "E", "A", "B", "C", "D", "A",
  10. "B" };
  11. int[] results = new int[array.length];
  12. for (int i = 0; i < array.length; i++) {
  13. for (int j = 0; j < array.length; j++) {
  14. if (array[i].equals(array[j])) {
  15. results[i] = results[i] + 1;
  16. }
  17. }
  18. }
  19. System.out.print("The least frequent strings are: ");
  20. for (int i = 0; i < array.length; i++) {
  21. for (int j = 0; j < array.length; j++){
  22. if(i == results[j] && printedString < 5){
  23. System.out.print(array[i] + ", ");
  24. printedString++;
  25. }
  26. }
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement