Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sort {
- public static void main(String[] args) {
- new Sort().run();
- }
- public void run() {
- int printedString = 0;
- String[] array = { "A", "B", "C", "D", "E", "F", "G", "H", "A", "B", "C", "D", "E", "A", "B", "C", "D", "A",
- "B" };
- int[] results = new int[array.length];
- for (int i = 0; i < array.length; i++) {
- for (int j = 0; j < array.length; j++) {
- if (array[i].equals(array[j])) {
- results[i] = results[i] + 1;
- }
- }
- }
- System.out.print("The least frequent strings are: ");
- for (int i = 0; i < array.length; i++) {
- for (int j = 0; j < array.length; j++){
- if(i == results[j] && printedString < 5){
- System.out.print(array[i] + ", ");
- printedString++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement