This code is for a dice simulator. Rolling 2 dice and printing out the results in the form of a histogram. The code runs fine. It's just that I don't want to see the number percentages with the asterisks. Does anyone know how to get rid of those numbers before the asterisk?
Example of my output:
2: 2 **
3: 6 ******
4: 10 **********
Example of how I want the output to be:
2: **
3: ******
4: **********
import java.util.*; public class DiceSim { public static void main(String[] args) { Scanner Input = new Scanner(System.in); int[] frequency = new int [13]; //Declares the array int die, die2; int numbThrows; int asterisk; int total; double fractionOfReps; System.out.println("How many dice rolls would you like to simulate? "); numbThrows = Input.nextInt(); //Roll the dice for (int i=1; i<=numbThrows; i++) { die = (int)(Math.random()*6) + 1; die2 = (int)(Math.random()*6) + 1; total = die + die2; frequency[total]++; } System.out.println("DICE ROLLING SIMULATION RESULTS " + '\n' + "Each " + '\"' + "*" + '\"' + " represents 1% of the total number" + " of rolls."); System.out.println("Total number of rolls = " + numbThrows); //output dice rolls for (total=2; total<=numbThrows; total++) { System.out.print( " " + total + ": " + frequency[total] + " "); fractionOfReps = (float) frequency[total] / numbThrows; asterisk = (int) Math.round(fractionOfReps * 100); for (int i=0; i<asterisk; i++) { System.out.print("*"); } System.out.println(); } } }