0

Writing a rollDice method

I need to use the random number generation library and use 2 different ways to generate random numbers that simulate a dice roll. Pretty much a user will enter the number of times they will roll the dice and the output will print out how many times (and percentage) a total of 2 and a total of 7 will appear. Below is what I have so far. please advice: import java.util.Scanner; import java.util.Random; public class Dice { //jh15b public static void main(String[] args) { Scanner input = new Scanner (System.in); int N; //input of the number of times the dice will roll System.out.print("How many times would you like to roll the two dice? "); N = input.nextInt(); Random rnd = new Random(); int n1 = rnd.nextInt(); System.out.println(n1); for(int i=0; i<10; i++) { //print out dice's faces int n2 = 1+ rnd.nextInt(6); } } }

1st Mar 2019, 4:45 PM
Gary Hu
Gary Hu - avatar
2 Respostas
+ 2
I would change the for loop N is your input For (int i = 0; i < N; i++){ n1 = rnd.nextInt (6) + 1; n2 = rnd.nextInt (6)+ 1; //print the the two dices } For every roll you create new random numbers.
1st Mar 2019, 8:16 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
import random
1st Mar 2019, 8:58 PM
Ivan