Here are some various bits of code you can use to accomplish this.
Create array
int[] histogram = new int[13];
Increment a position in the array
histogram[id]++;
Print histogram
System.out.println("Histogram of rolls:" ); printHistogram(histogram);
Here are some helper functions as well.
private void printHistogram(int[] array) { for (int range = 0; range < array.length; range++) { String label = range + " : "; System.out.println(label + convertToStars(array[range])); } } private String convertToStars(int num) { StringBuilder builder = new StringBuilder(); for (int j = 0; j < num; j++) { builder.append('*'); } return builder.toString(); }
Code should be modified as needed.
Related Posts:
- Converting array to list in Java
- What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- Working with a List of Lists in Java
- How to convert jsonString to JSONObject in Java
- what does “>>>” mean in java?
- How to convert List
to int[] in Java? - How to convert int[] into List
in Java? - In Java, how to append a string more efficiently?
- Java ArrayList for integers
- java.lang.ArrayIndexOutOfBoundsException: 4 Error
- Convert ArrayList
to java.util.List [closed] - Java says this method has a constructor name
- Using the Pythagorean theorem with Java
- How do I determine whether an array contains a particular value in Java?
- How do I declare and initialize an array in Java?
- Convert list to array in Java [duplicate]
- Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array
- How to print elements in a vector c++
- Converting String to “Character” array in Java
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- TypeScript Objects as Dictionary types as in C#
- string to string array conversion in java
- Data type not understood while creating a NumPy array
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- How do I reverse an int array in Java?
- Are vectors passed to functions by value or by reference in C++
- How do I declare a 2d array in C++ using new?
- How to split a String by space
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- How to create a sub array from another array in Java?
- How to split a string into an array in Bash?
- Getting “conflicting types for function” in C, why?
- Array ArrayList python equivalent
- Double array initialization in Java
- Array of arrays (Python/NumPy)
- I want to declare an empty array in java and then I want do update it but the code is not working
- Calculating Standard Deviation & Variance in C++
- What is the difference between String[] and String… in Java?
- How to convert an ArrayList containing Integers to primitive int array?
- Error: can only iterate over an array or an instance of java.lang.Iterable
- Where is Java’s Array indexOf?
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- Convert an integer to an array of characters : java
- What does ** do in C language?
- How to efficiently remove duplicates from an array without using Set
- Correct way of looping through C++ arrays
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- Will Arrays.sort() increase time complexity and space time complexity?
- How can I concatenate two arrays in Java?
- How do I create an array of strings in C?
- method in class cannot be applied to given types
- How do I remove an array item in TypeScript?
- How can I create an Array of ArrayLists?
- How can I check whether an array is null / empty?
- Add an object to an Array of a custom class
- Random shuffling of an array
- How to convert int[] to Integer[] in Java?
- Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException
- How to create an array of strings in C?
- Initialization from incompatible pointer type warning when assigning to a pointer
- “Cannot create generic array of ..” – how to create an Array of Map
? - Java Comparator class to sort arrays
- List of Arrays in Java
- How to sort an array of objects in Java?
- local variables referenced from an inner class must be final or effectively final
- Bank Account Java Program
- What is the default initialization of an array in Java?
- Java, Shifting Elements in an Array
- Counting an Occurrence in an Array (Java)
- How to create a generic array in Java?
- Badly placed ()’s error with the following shell script
- Empty an array in Java / processing
- type any? has no subscript members
- IndexError: index 10 is out of bounds for axis 0 with size 10
- Add String Array to ArrayList
- How to print the data in byte array as characters?
- Java Array Sort descending?
- Finding the size of a char array in Java
- Any way to declare an array in-line?
- Error array dimension missing
- How can I find the number of elements in an array?
- Array type char[] is not assignable
- Create a two dimensional string array anArray[2][2]
- Two-dimensional array in Swift
- Parameter name omitted error?
- C char array initialization
- How to iterate through table in Lua?
- How do you set one array’s values to another array’s values in Java?
- How to sort in-place using the merge sort algorithm?
- java.lang.ArrayIndexOutOfBoundsException: 0
- How to increase the size of an array in Java?
- VBA array sort function?
- Array to Hash Ruby
- Create an empty object in JavaScript with {} or new Object()?
- GCC: Array type has incomplete element type
- Multidimensional Arrays lengths in Java
- Checking if a key exists in a JavaScript object?
- creating array without declaring the size – java