Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Directions: the code below tells me the first, second and third most relevant nu

ID: 3742331 • Letter: D

Question

Directions: the code below tells me the first, second and third most relevant numbers that popped up in the array, as well as how many times they popped up in the code. It also gives me the numbers chance percentage of it being in the range of (1-5)(6-10)(11-15)(16-20)(21-25)(26-30)(31-35)(36-40)(41-45)(46-50) (51-55)(56-60)(61-65)(66-70) Only 1 throught 70 Eample below. It also tells me the chance percentage of the precise numbers 1-70. 1 All the way to 70 . Add to the code to the left of Example: Chances (1-5) and the rest of the chances :Example below. Add to the code below giving me the exact percenatage of number array in the 10s,20s,30s,40s,50s,60s,70 include 1-9 as well. have the percentage for all 6 arrays.

I Will thumbs up good work thanks!!

/**

Output:

First Relevance Number: output:1,17,31,64,70,2

Most relevant numbers came up (1 came up 12 times) (17 came up 7 times) (31 came up 7 times) (64 came up 5 times) (70 came up 7 times) (2 came up 6 times)

Second Relevance Number: output:2,13,23,56,59,9

Most relevant numbers came up (2 came up 9 times) (13 came up 5 times) (23 came up 4 times) (56 came up 4 times) (59 came up 6 times) (9 came up 5 times)

Third Relevance Number: output:4,11,18,66,67,1

Most relevant numbers came up (4 came up 7 times) (11 came up 4 times) (18 came up 3 times) (66 came up 3 times) (67 came up 5 times) (1 came up 4 times)


For array1:
(put code here )Chances 1-5 = 42.68% (Num 1 chance 14.63%) (Num 2 chance 10.98%) (Num 3 chance 4.88%) (Num 4 chance 8.54%) (Num 5 chance 3.66%)
(put code here )Chances 6-10 = 20.73% (Num 6 chance 7.32%) (Num 7 chance 4.88%) (Num 8 chance 2.44%) (Num 9 chance 0.00%) (Num 10 chance 6.10%)
(put code here)Chances 11-15 = 13.41% (Num 11 chance 3.66%) (Num 12 chance 2.44%) (Num 13 chance 1.22%) (Num 14 chance 6.10%) (Num 15 chance 0.00%)
(put code here)Chances 16-20 = 10.98% (Num 16 chance 4.88%) (Num 17 chance 4.88%) (Num 18 chance 0.00%) (Num 19 chance 0.00%) (Num 20 chance 1.22%)
(put code here)Chances 21-25 = 4.88% (Num 21 chance 2.44%) (Num 22 chance 1.22%) (Num 23 chance 0.00%) (Num 24 chance 1.22%) (Num 25 chance 0.00%)
(put code here)Chances 26-30 = 4.88% (Num 26 chance 0.00%) (Num 27 chance 0.00%) (Num 28 chance 3.66%) (Num 29 chance 1.22%) (Num 30 chance 0.00%)
(put code here)Chances 31-35 = 1.22% (Num 31 chance 1.22%) (Num 32 chance 0.00%) (Num 33 chance 0.00%) (Num 34 chance 0.00%) (Num 35 chance 0.00%)
(put code here)Chances 36-40 = 0.00% (Num 36 chance 0.00%) (Num 37 chance 0.00%) (Num 38 chance 0.00%) (Num 39 chance 0.00%) (Num 40 chance 0.00%)
(put code here)Chances 41-45 = 0.00% (Num 41 chance 0.00%) (Num 42 chance 0.00%) (Num 43 chance 0.00%) (Num 44 chance 0.00%) (Num 45 chance 0.00%)
(put code here)Chances 46-50 = 0.00% (Num 46 chance 0.00%) (Num 47 chance 0.00%) (Num 48 chance 0.00%) (Num 49 chance 0.00%) (Num 50 chance 0.00%)
(put code here)Chances 51-55 = 0.00% (Num 51 chance 0.00%) (Num 52 chance 0.00%) (Num 53 chance 0.00%) (Num 54 chance 0.00%) (Num 55 chance 0.00%)
(put code here)Chances 56-60 = 0.00% (Num 56 chance 0.00%) (Num 57 chance 0.00%) (Num 58 chance 0.00%) (Num 59 chance 0.00%) (Num 60 chance 0.00%)
(put code here)Chances 61-65 = 0.00% (Num 61 chance 0.00%) (Num 62 chance 0.00%) (Num 63 chance 0.00%) (Num 64 chance 0.00%) (Num 65 chance 0.00%)
(put code here)Chances 66-70 = 0.00% (Num 66 chance 0.00%) (Num 67 chance 0.00%) (Num 68 chance 0.00%) (Num 69 chance 0.00%) (Num 70 chance 0.00%)

For array2:
(Put code here)Chances 1-5 = 6.80% (Num 1 chance 0.00%) (Num 2 chance 0.97%) (Num 3 chance 1.94%) (Num 4 chance 0.97%) (Num 5 chance 2.91%)
Put code here)Chances 6-10 = 10.68% (Num 6 chance 2.91%) (Num 7 chance 2.91%) (Num 8 chance 0.97%) (Num 9 chance 0.97%) (Num 10 chance 2.91%)
Put code here)Chances 11-15 = 19.42% (Num 11 chance 3.88%) (Num 12 chance 3.88%) (Num 13 chance 4.85%) (Num 14 chance 2.91%) (Num 15 chance 3.88%)
Put code here)Chances 16-20 = 15.53% (Num 16 chance 2.91%) (Num 17 chance 6.80%) (Num 18 chance 1.94%) (Num 19 chance 1.94%) (Num 20 chance 1.94%)
Put code here)Chances 21-25 = 10.68% (Num 21 chance 0.00%) (Num 22 chance 2.91%) (Num 23 chance 2.91%) (Num 24 chance 2.91%) (Num 25 chance 1.94%)
Put code here)Chances 26-30 = 12.62% (Num 26 chance 2.91%) (Num 27 chance 0.00%) (Num 28 chance 4.85%) (Num 29 chance 2.91%) (Num 30 chance 1.94%)
Put code here)Chances 31-35 = 9.71% (Num 31 chance 0.97%) (Num 32 chance 1.94%) (Num 33 chance 2.91%) (Num 34 chance 2.91%) (Num 35 chance 0.97%)
Put code here)Chances 36-40 = 7.77% (Num 36 chance 0.97%) (Num 37 chance 2.91%) (Num 38 chance 2.91%) (Num 39 chance 0.97%) (Num 40 chance 0.00%)
Put code here)Chances 41-45 = 3.88% (Num 41 chance 1.94%) (Num 42 chance 0.97%) (Num 43 chance 0.00%) (Num 44 chance 0.00%) (Num 45 chance 0.97%)
Put code here)Chances 46-50 = 0.00% (Num 46 chance 0.00%) (Num 47 chance 0.00%) (Num 48 chance 0.00%) (Num 49 chance 0.00%) (Num 50 chance 0.00%)
Put code here)Chances 51-55 = 1.94% (Num 51 chance 0.97%) (Num 52 chance 0.00%) (Num 53 chance 0.00%) (Num 54 chance 0.97%) (Num 55 chance 0.00%)
Put code here)Chances 56-60 = 0.97% (Num 56 chance 0.00%) (Num 57 chance 0.97%) (Num 58 chance 0.00%) (Num 59 chance 0.00%) (Num 60 chance 0.00%)
Put code here)Chances 61-65 = 0.00% (Num 61 chance 0.00%) (Num 62 chance 0.00%) (Num 63 chance 0.00%) (Num 64 chance 0.00%) (Num 65 chance 0.00%)
Put code here)Chances 66-70 = 0.00% (Num 66 chance 0.00%) (Num 67 chance 0.00%) (Num 68 chance 0.00%) (Num 69 chance 0.00%) (Num 70 chance 0.00%)


For array3:
Put code here)Chances 1-5 = 2.70% (Num 1 chance 0.00%) (Num 2 chance 0.00%) (Num 3 chance 0.00%) (Num 4 chance 1.35%) (Num 5 chance 1.35%)
Put code here)Chances 6-10 = 1.35% (Num 6 chance 0.00%) (Num 7 chance 0.00%) (Num 8 chance 0.00%) (Num 9 chance 0.00%) (Num 10 chance 1.35%)
Put code here)Chances 11-15 = 5.41% (Num 11 chance 1.35%) (Num 12 chance 0.00%) (Num 13 chance 1.35%) (Num 14 chance 1.35%) (Num 15 chance 1.35%)
Put code here)Chances 16-20 = 5.41% (Num 16 chance 0.00%) (Num 17 chance 0.00%) (Num 18 chance 4.05%) (Num 19 chance 0.00%) (Num 20 chance 1.35%)
Put code here)Chances 21-25 = 10.81% (Num 21 chance 4.05%) (Num 22 chance 0.00%) (Num 23 chance 5.41%) (Num 24 chance 1.35%) (Num 25 chance 0.00%)
Put code here)Chances 26-30 = 8.11% (Num 26 chance 2.70%) (Num 27 chance 0.00%) (Num 28 chance 1.35%) (Num 29 chance 1.35%) (Num 30 chance 2.70%)
Put code here)Chances 31-35 = 14.86% (Num 31 chance 9.46%) (Num 32 chance 1.35%) (Num 33 chance 2.70%) (Num 34 chance 1.35%) (Num 35 chance 0.00%)
Put code here)Chances 36-40 = 14.86% (Num 36 chance 1.35%) (Num 37 chance 2.70%) (Num 38 chance 2.70%) (Num 39 chance 5.41%) (Num 40 chance 2.70%)
Put code here)Chances 41-45 = 10.81% (Num 41 chance 2.70%) (Num 42 chance 2.70%) (Num 43 chance 1.35%) (Num 44 chance 2.70%) (Num 45 chance 1.35%)
Put code here)Chances 46-50 = 6.76% (Num 46 chance 1.35%) (Num 47 chance 4.05%) (Num 48 chance 1.35%) (Num 49 chance 0.00%) (Num 50 chance 0.00%)
Put code here)Chances 51-55 = 10.81% (Num 51 chance 4.05%) (Num 52 chance 1.35%) (Num 53 chance 1.35%) (Num 54 chance 1.35%) (Num 55 chance 2.70%)
Put code here)Chances 56-60 = 5.41% (Num 56 chance 0.00%) (Num 57 chance 1.35%) (Num 58 chance 1.35%) (Num 59 chance 1.35%) (Num 60 chance 1.35%)
Put code here)Chances 61-65 = 2.70% (Num 61 chance 1.35%) (Num 62 chance 1.35%) (Num 63 chance 0.00%) (Num 64 chance 0.00%) (Num 65 chance 0.00%)
Put code here)Chances 66-70 = 0.00% (Num 66 chance 0.00%) (Num 67 chance 0.00%) (Num 68 chance 0.00%) (Num 69 chance 0.00%) (Num 70 chance 0.00%)


For array4:
Put code here)Chances 1-5 = 0.00% (Num 1 chance 0.00%) (Num 2 chance 0.00%) (Num 3 chance 0.00%) (Num 4 chance 0.00%) (Num 5 chance 0.00%)
Put code here)Chances 6-10 = 2.67% (Num 6 chance 1.33%) (Num 7 chance 0.00%) (Num 8 chance 1.33%) (Num 9 chance 0.00%) (Num 10 chance 0.00%)
Put code here)Chances 11-15 = 1.33% (Num 11 chance 0.00%) (Num 12 chance 1.33%) (Num 13 chance 0.00%) (Num 14 chance 0.00%) (Num 15 chance 0.00%)
Put code here)Chances 16-20 = 1.33% (Num 16 chance 0.00%) (Num 17 chance 0.00%) (Num 18 chance 1.33%) (Num 19 chance 0.00%) (Num 20 chance 0.00%)
Put code here)Chances 21-25 = 9.33% (Num 21 chance 1.33%) (Num 22 chance 4.00%) (Num 23 chance 0.00%) (Num 24 chance 1.33%) (Num 25 chance 2.67%)
Put code here)Chances 26-30 = 4.00% (Num 26 chance 2.67%) (Num 27 chance 0.00%) (Num 28 chance 0.00%) (Num 29 chance 1.33%) (Num 30 chance 0.00%)
Put code here)Chances 31-35 = 6.67% (Num 31 chance 1.33%) (Num 32 chance 1.33%) (Num 33 chance 2.67%) (Num 34 chance 1.33%) (Num 35 chance 0.00%)
Put code here)Chances 36-40 = 4.00% (Num 36 chance 2.67%) (Num 37 chance 0.00%) (Num 38 chance 1.33%) (Num 39 chance 0.00%) (Num 40 chance 0.00%)
Put code here)Chances 41-45 = 13.33% (Num 41 chance 1.33%) (Num 42 chance 6.67%) (Num 43 chance 1.33%) (Num 44 chance 2.67%) (Num 45 chance 1.33%)
Put code here)Chances 46-50 = 17.33% (Num 46 chance 4.00%) (Num 47 chance 2.67%) (Num 48 chance 1.33%) (Num 49 chance 6.67%) (Num 50 chance 2.67%)
Put code here)Chances 51-55 = 6.67% (Num 51 chance 1.33%) (Num 52 chance 0.00%) (Num 53 chance 2.67%) (Num 54 chance 1.33%) (Num 55 chance 1.33%)
Put code here)Chances 56-60 = 10.67% (Num 56 chance 5.33%) (Num 57 chance 0.00%) (Num 58 chance 1.33%) (Num 59 chance 1.33%) (Num 60 chance 2.67%)
Put code here)Chances 61-65 = 13.33% (Num 61 chance 1.33%) (Num 62 chance 1.33%) (Num 63 chance 2.67%) (Num 64 chance 6.67%) (Num 65 chance 1.33%)
Put code here)Chances 66-70 = 8.00% (Num 66 chance 4.00%) (Num 67 chance 1.33%) (Num 68 chance 1.33%) (Num 69 chance 0.00%) (Num 70 chance 1.33%)


For array5:
Chances 1-5 = 0.00% (Num 1 chance 0.00%) (Num 2 chance 0.00%) (Num 3 chance 0.00%) (Num 4 chance 0.00%) (Num 5 chance 0.00%)
Chances 6-10 = 2.70% (Num 6 chance 2.70%) (Num 7 chance 0.00%) (Num 8 chance 0.00%) (Num 9 chance 0.00%) (Num 10 chance 0.00%)
Chances 11-15 = 0.00% (Num 11 chance 0.00%) (Num 12 chance 0.00%) (Num 13 chance 0.00%) (Num 14 chance 0.00%) (Num 15 chance 0.00%)
Chances 16-20 = 0.00% (Num 16 chance 0.00%) (Num 17 chance 0.00%) (Num 18 chance 0.00%) (Num 19 chance 0.00%) (Num 20 chance 0.00%)
Chances 21-25 = 1.35% (Num 21 chance 0.00%) (Num 22 chance 1.35%) (Num 23 chance 0.00%) (Num 24 chance 0.00%) (Num 25 chance 0.00%)
Chances 26-30 = 1.35% (Num 26 chance 0.00%) (Num 27 chance 0.00%) (Num 28 chance 1.35%) (Num 29 chance 0.00%) (Num 30 chance 0.00%)
Chances 31-35 = 1.35% (Num 31 chance 0.00%) (Num 32 chance 0.00%) (Num 33 chance 0.00%) (Num 34 chance 1.35%) (Num 35 chance 0.00%)
Chances 36-40 = 4.05% (Num 36 chance 0.00%) (Num 37 chance 1.35%) (Num 38 chance 0.00%) (Num 39 chance 1.35%) (Num 40 chance 1.35%)
Chances 41-45 = 10.81% (Num 41 chance 1.35%) (Num 42 chance 2.70%) (Num 43 chance 4.05%) (Num 44 chance 1.35%) (Num 45 chance 1.35%)
Chances 46-50 = 6.76% (Num 46 chance 1.35%) (Num 47 chance 1.35%) (Num 48 chance 1.35%) (Num 49 chance 1.35%) (Num 50 chance 1.35%)
Chances 51-55 = 10.81% (Num 51 chance 1.35%) (Num 52 chance 4.05%) (Num 53 chance 2.70%) (Num 54 chance 0.00%) (Num 55 chance 2.70%)
Chances 56-60 = 17.57% (Num 56 chance 4.05%) (Num 57 chance 1.35%) (Num 58 chance 4.05%) (Num 59 chance 8.11%) (Num 60 chance 0.00%)
Chances 61-65 = 14.86% (Num 61 chance 4.05%) (Num 62 chance 5.41%) (Num 63 chance 0.00%) (Num 64 chance 4.05%) (Num 65 chance 1.35%)
Chances 66-70 = 24.32% (Num 66 chance 5.41%) (Num 67 chance 6.76%) (Num 68 chance 2.70%) (Num 69 chance 0.00%) (Num 70 chance 9.46%)


For array6:
Chances 1-5 = 22.37% (Num 1 chance 5.26%) (Num 2 chance 7.89%) (Num 3 chance 2.63%) (Num 4 chance 3.95%) (Num 5 chance 2.63%)
Chances 6-10 = 21.05% (Num 6 chance 3.95%) (Num 7 chance 3.95%) (Num 8 chance 2.63%) (Num 9 chance 6.58%) (Num 10 chance 3.95%)
Chances 11-15 = 22.37% (Num 11 chance 6.58%) (Num 12 chance 5.26%) (Num 13 chance 3.95%) (Num 14 chance 5.26%) (Num 15 chance 1.32%)
Chances 16-20 = 13.16% (Num 16 chance 3.95%) (Num 17 chance 5.26%) (Num 18 chance 0.00%) (Num 19 chance 2.63%) (Num 20 chance 1.32%)
Chances 21-25 = 21.05% (Num 21 chance 2.63%) (Num 22 chance 6.58%) (Num 23 chance 3.95%) (Num 24 chance 3.95%) (Num 25 chance 3.95%)
Chances 26-30 = 0.00% (Num 26 chance 0.00%) (Num 27 chance 0.00%) (Num 28 chance 0.00%) (Num 29 chance 0.00%) (Num 30 chance 0.00%)
Chances 31-35 = 0.00% (Num 31 chance 0.00%) (Num 32 chance 0.00%) (Num 33 chance 0.00%) (Num 34 chance 0.00%) (Num 35 chance 0.00%)
Chances 36-40 = 0.00% (Num 36 chance 0.00%) (Num 37 chance 0.00%) (Num 38 chance 0.00%) (Num 39 chance 0.00%) (Num 40 chance 0.00%)
Chances 41-45 = 0.00% (Num 41 chance 0.00%) (Num 42 chance 0.00%) (Num 43 chance 0.00%) (Num 44 chance 0.00%) (Num 45 chance 0.00%)
Chances 46-50 = 0.00% (Num 46 chance 0.00%) (Num 47 chance 0.00%) (Num 48 chance 0.00%) (Num 49 chance 0.00%) (Num 50 chance 0.00%)
Chances 51-55 = 0.00% (Num 51 chance 0.00%) (Num 52 chance 0.00%) (Num 53 chance 0.00%) (Num 54 chance 0.00%) (Num 55 chance 0.00%)
Chances 56-60 = 0.00% (Num 56 chance 0.00%) (Num 57 chance 0.00%) (Num 58 chance 0.00%) (Num 59 chance 0.00%) (Num 60 chance 0.00%)
Chances 61-65 = 0.00% (Num 61 chance 0.00%) (Num 62 chance 0.00%) (Num 63 chance 0.00%) (Num 64 chance 0.00%) (Num 65 chance 0.00%)
Chances 66-70 = 0.00% (Num 66 chance 0.00%) (Num 67 chance 0.00%) (Num 68 chance 0.00%) (Num 69 chance 0.00%) (Num 70 chance 0.00%)


BUILD SUCCESSFUL (total time: 0 seconds)

/*

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Chag {

public static TreeMap<Integer, Integer> getFrequencyMap(int num[]) {
HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
for (int i = 0; i < num.length; i++) {
if (counts.containsKey(num[i])) {
int c = counts.get(num[i]) + 1;
counts.put(num[i], c);
}
else {
counts.put(num[i], 1);
}
}
ValueComparator<Integer, Integer> bvc = new ValueComparator<Integer, Integer>(counts);
TreeMap<Integer, Integer> sortedMap = new TreeMap<Integer, Integer>(bvc);
sortedMap.putAll(counts);
return sortedMap;
}

public static void printChances(int arr[], TreeMap<Integer, Integer> sortedMap) {

int chances = 1; // starting value of first range

// loops until the range crosses 70
while ((chances + 4) <= 70) {

double numChance[] = new double[5];

// count count of occurrences of values between chance and chance+4
int count = 0;

// inner loop to find the above count
for (int j = chances; j < chances + 5; j++) {

// checking if the first map contains j
if (sortedMap.containsKey(j)) {
// adding to the count
count += sortedMap.get(j);

numChance[j-chances] = sortedMap.get(j) * 100.0 /arr.length;
}

}

// finding the percentage
double percentage = (double) count * 100.0 / arr.length;

// printing the percentage with a precision of two decimal points
System.out.printf("Chances %d-%d = %.2f%% ", chances, chances + 4, percentage);

for (int j = 0; j < 5; j++) {
System.out.printf("(Num %d chance %.2f%%) ", chances + j, numChance[j]);   
}
System.out.printf(" ");   

chances += 5;
}
System.out.printf(" ");   
}

public static void main(String args[]) {
int num1[] = { 1,21,1,2,13,2,17,2,11,+
1,1,14,22,5,2,118,4,2,2,3,1,12,8,5,16,4,11,7,4,14,1,6,7,1,+
24,10,7,17,14,5,28,14,1,29,10,2,6,3,17,16,28,1,4,10,1,28,4,8,6,14,16,10,16,3,+
3,1,6,1,10,6,17,20,6,31,2,7,21,12,4,11,4,2 };
int num2[] = { 6,16,31,26,3,13,28,15,32,2,14,41,22,17,10,35,32,25,6,13,+
11,3,30,33,24,11,14,17,26,34,38,15,5,7,29,19,15,34,9,13,33,29,28,25,8,38,13,30,+
17,4,28,17,11,19,38,12,34,17,5,41,16,6,12,11,18,29,20,42,10,12,20,37,12,23,+
37,15,22,17,36,7,26,14,23,54,22,28,57,24,23,45,7,16,33,18,51,10,39,28,24,+
37,5,17,13 };
int num3[] = { 4,30,61,39,45,47,29,11,28,37,5,33,+
41,52,55,51,21,53,44,40,39,10,20,38,31,18,44,32,31,51,39,31,43,23,51,26,58,+
18,26,42,21,13,23,48,15,30,23,23,33,31,39,47,18,36,24,46,37,+
40,47,55,21,38,60,42,31,62,57,54,31,34,41,14,59,31 };
int num4[] = { 32,34,18,22,21,54,64,49,66,22,56,50,49,49,65,47,8,44,48,+
62,58,64,36,64,36,64,49,12,55,63,47,42,43,42,46,56,53,64,33,+
60,46,24,53,38,31,49,29,46,67,59,33,42,+
44,25,60,42,41,51,6,22,42,68,56,66,56,26,61,45,25,73,66,63,50,+
26,70 };
int num5[] = {55,22,59,37,56,46,42,62,62,67,68,70,56,44,70,51,70,+
56,52,66,67,68,48,45,65,59,53,67,62,59,59,59,70,52,61,66,+
39,64,43,58,43,58,49,47,58,40,57,43,55,66,70,62,41,42,70,67,59,+
61,64,50,70,28,53,52,64,73,6,67,74,75,66,61,34,6 };
int num6[] = { 17,6,2,2,1,12,2,14,16,23,23,19,20,14,6,3,13,4,17,+
2,25,9,11,21,22,13,21,1,11,10,4,9,11,17,22,22,8,23,9,14,+
16,1,14,25,4,24,1,7,10,22,7,25,16,9,24,22,8,5,19,24,11,3,+
12,13,6,9,11,12,2,12,15,10,7,2,17,5 };//20 came 5 22 came up 5 23 came 5 times

TreeMap<Integer, Integer> sortedMap1 = getFrequencyMap(num1);
TreeMap<Integer, Integer> sortedMap2 = getFrequencyMap(num2);
TreeMap<Integer, Integer> sortedMap3 = getFrequencyMap(num3);
TreeMap<Integer, Integer> sortedMap4 = getFrequencyMap(num4);
TreeMap<Integer, Integer> sortedMap5 = getFrequencyMap(num5);
TreeMap<Integer, Integer> sortedMap6 = getFrequencyMap(num6);

for (int i = 0; i < 3; i++) {
if (i == 0) {
System.out.print("First Relevance Number: output:");
} else if (i == 1) {
System.out.print(" Second Relevance Number: output:");
} else if (i == 2) {
System.out.print(" Third Relevance Number: output:");
}

// storing all the keys (relevant numbers) in integer variables
int v1 = (Integer) sortedMap1.keySet().toArray()[i];
int v2 = (Integer) sortedMap2.keySet().toArray()[i];
int v3 = (Integer) sortedMap3.keySet().toArray()[i];
int v4 = (Integer) sortedMap4.keySet().toArray()[i];
int v5 = (Integer) sortedMap5.keySet().toArray()[i];
int v6 = (Integer) sortedMap6.keySet().toArray()[i];
// displaying them
System.out.print(v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5
+ "," + v6);
System.out.println();
System.out.print(" Most relevant numbers came up ");
// displaying relevant numbers and their number of occurrences
System.out.print("(" + v1 + " came up " + sortedMap1.get(v1)
+ " times) ");
System.out.print("(" + v2 + " came up " + sortedMap2.get(v2)
+ " times) ");
System.out.print("(" + v3 + " came up " + sortedMap3.get(v3)
+ " times) ");
System.out.print("(" + v4 + " came up " + sortedMap4.get(v4)
+ " times) ");
System.out.print("(" + v5 + " came up " + sortedMap5.get(v5)
+ " times) ");
System.out.print("(" + v6 + " came up " + sortedMap6.get(v6)
+ " times) ");
System.out.println();
}


System.out.println(" For array1:");
printChances(num1, sortedMap1);

System.out.println("For array2:");
printChances(num2, sortedMap2);

System.out.println("For array3:");
printChances(num3, sortedMap3);

System.out.println("For array4:");
printChances(num4, sortedMap4);

System.out.println("For array5:");
printChances(num5, sortedMap5);

System.out.println("For array6:");
printChances(num6, sortedMap6);

}
}

class ValueComparator<T1, T2 extends Comparable<T2>> implements Comparator<T1> {
Map<T1, T2> base;
public ValueComparator(Map<T1, T2> base) {
this.base = base;
}
@Override
public int compare(T1 k1, T1 k2) {
if (base.containsKey(k1) && base.containsKey(k2)) {
T2 val1 = base.get(k1);
T2 val2 = base.get(k2);
return val2.compareTo(val1);
}
return -1;
}
}

Explanation / Answer

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Cheggs {

   public static TreeMap<Integer, Integer> getFrequencyMap(int num[]) {
       HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
       for (int i = 0; i < num.length; i++) {
           if (counts.containsKey(num[i])) {
               int c = counts.get(num[i]) + 1;
               counts.put(num[i], c);
           }
           else {
               counts.put(num[i], 1);
           }
       }
       ValueComparator<Integer, Integer> bvc = new ValueComparator<Integer, Integer>(counts);
       TreeMap<Integer, Integer> sortedMap = new TreeMap<Integer, Integer>(bvc);
       sortedMap.putAll(counts);
       return sortedMap;
   }

   public static void printChances(int arr[], TreeMap<Integer, Integer> sortedMap) {

       int chances = 1; // starting value of first range

       // loops until the range crosses 70
       while ((chances + 4) <= 70) {

           double numChance[] = new double[5];

           // count count of occurrences of values between chance and chance+4
           int count = 0;

           // inner loop to find the above count
           for (int j = chances; j < chances + 5; j++) {

               // checking if the first map contains j
               if (sortedMap.containsKey(j)) {
                   // adding to the count
                   count += sortedMap.get(j);

                   numChance[j-chances] = sortedMap.get(j) * 100.0 /arr.length;
               }

           }

           // finding the percentage
           double percentage = (double) count * 100.0 / arr.length;

           // printing the percentage with a precision of two decimal points
           System.out.printf("Chances %d-%d = %.2f%% ", chances, chances + 4, percentage);

           for (int j = 0; j < 5; j++) {
               System.out.printf("(Num %d chance %.2f%%) ", chances + j, numChance[j]);                
           }
           System.out.printf(" ");        

           chances += 5;
       }
   System.out.printf(" ");      
   }

   public static void main(String args[]) {
       int num1[] = { 1,21,1,2,13,2,17,2,11,+
       1,1,14,22,5,2,118,4,2,2,3,1,12,8,5,16,4,11,7,4,14,1,6,7,1,+
       24,10,7,17,14,5,28,14,1,29,10,2,6,3,17,16,28,1,4,10,1,28,4,8,6,14,16,10,16,3,+
       3,1,6,1,10,6,17,20,6,31,2,7,21,12,4,11,4,2 };
       int num2[] = { 6,16,31,26,3,13,28,15,32,2,14,41,22,17,10,35,32,25,6,13,+
       11,3,30,33,24,11,14,17,26,34,38,15,5,7,29,19,15,34,9,13,33,29,28,25,8,38,13,30,+
       17,4,28,17,11,19,38,12,34,17,5,41,16,6,12,11,18,29,20,42,10,12,20,37,12,23,+
       37,15,22,17,36,7,26,14,23,54,22,28,57,24,23,45,7,16,33,18,51,10,39,28,24,+
       37,5,17,13 };
       int num3[] = { 4,30,61,39,45,47,29,11,28,37,5,33,+
       41,52,55,51,21,53,44,40,39,10,20,38,31,18,44,32,31,51,39,31,43,23,51,26,58,+
       18,26,42,21,13,23,48,15,30,23,23,33,31,39,47,18,36,24,46,37,+
       40,47,55,21,38,60,42,31,62,57,54,31,34,41,14,59,31 };
       int num4[] = { 32,34,18,22,21,54,64,49,66,22,56,50,49,49,65,47,8,44,48,+
       62,58,64,36,64,36,64,49,12,55,63,47,42,43,42,46,56,53,64,33,+
       60,46,24,53,38,31,49,29,46,67,59,33,42,+
       44,25,60,42,41,51,6,22,42,68,56,66,56,26,61,45,25,73,66,63,50,+
       26,70 };
       int num5[] = {55,22,59,37,56,46,42,62,62,67,68,70,56,44,70,51,70,+
       56,52,66,67,68,48,45,65,59,53,67,62,59,59,59,70,52,61,66,+
       39,64,43,58,43,58,49,47,58,40,57,43,55,66,70,62,41,42,70,67,59,+
       61,64,50,70,28,53,52,64,73,6,67,74,75,66,61,34,6 };
       int num6[] = { 17,6,2,2,1,12,2,14,16,23,23,19,20,14,6,3,13,4,17,+
       2,25,9,11,21,22,13,21,1,11,10,4,9,11,17,22,22,8,23,9,14,+
       16,1,14,25,4,24,1,7,10,22,7,25,16,9,24,22,8,5,19,24,11,3,+
       12,13,6,9,11,12,2,12,15,10,7,2,17,5 };//20 came 5 22 came up 5 23 came 5 times

       TreeMap<Integer, Integer> sortedMap1 = getFrequencyMap(num1);
       TreeMap<Integer, Integer> sortedMap2 = getFrequencyMap(num2);
       TreeMap<Integer, Integer> sortedMap3 = getFrequencyMap(num3);
       TreeMap<Integer, Integer> sortedMap4 = getFrequencyMap(num4);
       TreeMap<Integer, Integer> sortedMap5 = getFrequencyMap(num5);
       TreeMap<Integer, Integer> sortedMap6 = getFrequencyMap(num6);

       for (int i = 0; i < 3; i++) {
           if (i == 0) {
               System.out.print("First Relevance Number: output:");
           } else if (i == 1) {
               System.out.print(" Second Relevance Number: output:");
           } else if (i == 2) {
               System.out.print(" Third Relevance Number: output:");
           }

           // storing all the keys (relevant numbers) in integer variables
           int v1 = (Integer) sortedMap1.keySet().toArray()[i];
           int v2 = (Integer) sortedMap2.keySet().toArray()[i];
           int v3 = (Integer) sortedMap3.keySet().toArray()[i];
           int v4 = (Integer) sortedMap4.keySet().toArray()[i];
           int v5 = (Integer) sortedMap5.keySet().toArray()[i];
           int v6 = (Integer) sortedMap6.keySet().toArray()[i];
           // displaying them
           System.out.print(v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5
           + "," + v6);
           System.out.println();
           System.out.print(" Most relevant numbers came up ");
           // displaying relevant numbers and their number of occurrences
           System.out.print("(" + v1 + " came up " + sortedMap1.get(v1)
           + " times) ");
           System.out.print("(" + v2 + " came up " + sortedMap2.get(v2)
           + " times) ");
           System.out.print("(" + v3 + " came up " + sortedMap3.get(v3)
           + " times) ");
           System.out.print("(" + v4 + " came up " + sortedMap4.get(v4)
           + " times) ");
           System.out.print("(" + v5 + " came up " + sortedMap5.get(v5)
           + " times) ");
           System.out.print("(" + v6 + " came up " + sortedMap6.get(v6)
           + " times) ");
           System.out.println();
       }


       System.out.println(" For array1:");
       printChances(num1, sortedMap1);

       System.out.println("For array2:");
       printChances(num2, sortedMap2);

       System.out.println("For array3:");
       printChances(num3, sortedMap3);

       System.out.println("For array4:");
       printChances(num4, sortedMap4);

       System.out.println("For array5:");
       printChances(num5, sortedMap5);

       System.out.println("For array6:");
       printChances(num6, sortedMap6);

   }
}

class ValueComparator<T1, T2 extends Comparable<T2>> implements Comparator<T1> {
   Map<T1, T2> base;
   public ValueComparator(Map<T1, T2> base) {
   this.base = base;
   }
   @Override
   public int compare(T1 k1, T1 k2) {
       if (base.containsKey(k1) && base.containsKey(k2)) {
           T2 val1 = base.get(k1);
           T2 val2 = base.get(k2);
           return val2.compareTo(val1);
       }
       return -1;
   }
}

In your code, there is lot of code, i have concised that and also made the changes as you asked. Please try to write the code in modules always and try to reuse the code which you have written, that way you will have lesser code to maintain and find error. Thanks!

Do let me know in comments, if you have any concerns. PLease upvote, if you like the answer

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote