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

Given an array of integers containing values in the range 1 to 6, inclusive, ret

ID: 3829924 • Letter: G

Question

Given an array of integers containing values in the range 1 to 6, inclusive, return an array of size 6 containing a count of the number of times each of the six values occur. For example, in the array {3, 1, 1, 2, 4, 4, 4, 6} the number 1 occurs 2 times, the number 2 occurs 1 time, the number 3 occurs 1 time, the number 4 occurs 3 times, the number 5 occurs 0 times, and the number 6 occurs 1 time. diceStats([3, 1, 1, 2, 4, 4, 4, 6]) rightarrow [2, 1, 1, 3, 0, 1] dicestats([3, 3, 3, 5]) rightarrow [0, 0, 3, 0, 1, 0] dicestats([6, 6, 6, 6, 6]) rightarrow [0, 0, 0, 0, 0, 5]

Explanation / Answer

DicStatsTest.java

import java.util.Arrays;


public class DicStatsTest {

  
   public static void main(String[] args) {
           int a[] = {3,1,1,2,4,4,4,6};
           System.out.println(Arrays.toString(diceStats(a)));
   }
   public static int[] diceStats(int a[]){
       int diceCount[] = {0,0,0,0,0,0};
       for(int i: a){
           diceCount[i-1]++;
       }
       return diceCount;
   }

}

Output

[2, 1, 1, 3, 0, 1]

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