I need help fixing my java code so that its output should compute a random number of "*" not numbers:
I need help fixing my java code so that its output should compute a random number of "*" not numbers:
Like the image given not this output below:
dice number 1: 2
dice number 2: 1
dice number 3: 1
dice number 4: 0
dice number 5: 1
dice number 6: 0
Java code:
import java.util.*;
public class PrintRandomChart_Class_FallProject_1
{
public static void main(String[] args) {
System.out.println("This game requests a number from the player.");
System.out.println("The game then throws the dice that number of times.");
System.out.println("The game then displays a chart showing the number of ");
System.out.println("times the six dice faces appeared given");
System.out.println("the number of throws.");
System.out.println("Please enter the number of times that you would");
System.out.println("like the computer to throw the dice.");
Scanner sc= new Scanner(System.in);
int[] a = new int[6];
char c;
int diceFaceNumber;
do{
int n= sc.nextInt();
for(int i=0;i<6;i++){
a[i]=0;
}
for(int i=0;i<n;i++){
diceFaceNumber = (int)(Math.random() * 6) + 1;
int k=diceFaceNumber-1;
a[k]=a[k] + 1;
}
for(int i=0;i<6;i++){
System.out.println("dice number "+(i+1)+": "+a[i]);
}
System.out.print("Do you want to continue(Y/N): ");
c= sc.next().charAt(0);
System.out.println("Please enter the number of times that you would");
System.out.println("like the computer to throw the dice.");
}while(c!='N');
}
}
Step by step
Solved in 3 steps with 1 images