[Solved]Need Help Assignment Cannot Figure Digit Frequency Counting Instructions Code Far Write Pr Q37087561
I need help with this assignment. I cannot figure out the digitfrequency counting. Below are the instructions and my code sofar.
Write a program (NumberFrequency.java) to generate randomnumbers between a user specified range, then count and display thefrequencies of the most / least appeared numbers.
Sample Output
How many random numbers? 1000000 Enter the minimum number: 100Enter the maximum number: 200 Generated 1000000 random numbersbetween 100 (inclusive) and 200 (exclusive). Number 186 has themost occurrences (10197).
Number 117 has the least occurrences (9749).
import java.util.Scanner;
import java.util.*;
public class NumberFrequency {
public static void main(String[] args) {
int max, min, mostFreq = 0,leastFreq = 0, numCount;
Scanner sc = newScanner(System.in);
Random rand = new Random();
System.out.println(“How manyrandom numbers?”);
numCount = sc.nextInt();
System.out.println(“Enter theminimum number: “);
min = sc.nextInt();
System.out.println(“Enter themaximum number: “);
max = sc.nextInt();
int[] numbers = newint[numCount];
for (int i = 0; i <numbers.length; i++) {
numbers[i] =rand.nextInt((max – min) + 1) + min;
System.out.println(numbers[i]);
}
System.out.println();
for(inti=0;i<numbers.length;i++) {
for(int j=i+1;j<numbers.length; j++) {
if(numbers[i]>numbers[j]) {
int temp = numbers[j];
numbers[j]=numbers[i];
numbers[i]=temp;
}
}
System.out.println(numbers[i]);
}
//Arrays.sort(numbers);
//System.out.println(numbers);
int currCount = 0;
int maxCount = 0;
int minCount = 0;
for (int i = min; i <numbers.length; i++) {
currCount =1;
if (numbers[i]== numbers[i -1]) {
currCount++;
} else {
if (minCount < currCount) {
minCount = currCount;
mostFreq = numbers[i];
}
currCount = 1;
}
}
for (int i = max; i <numbers.length; i++) {
if (numbers[i]== numbers[i – 1]) {
maxCount++;
} else {
if (maxCount > currCount) {
maxCount = currCount;
leastFreq = numbers[i];
}
currCount = 1;
}
}
System.out.println(“Generated ” +numCount + ” random numbers between ” + min + ” (inclusive) and ” +max + ” (exclusive).”);
System.out.println(“Number ” +mostFreq + ” has the most occurences (” + maxCount + “)”);
System.out.println(“Number ” +leastFreq + ” has the least occurences (” + minCount + “)”);
}
}
Expert Answer
Answer to I need help with this assignment. I cannot figure out the digit frequency counting. Below are the instructions and my co… . . .
OR

