Dice Rolling Project (JAVA ONLY)

Back to General discussions forum

Java_Coder     2015-06-18 22:05:41

I was wondering what I was doing wrong in my code. I figured out how to generate the random integers, but I could not figure out how I should implement the algorithm to get the dice number. The directions to me weren't very clear on what I was supposed to do. Here is my code for what I have so far.

import java.util.Scanner; import java.io.*;

public class DiceRoll {

public static void main(String[] args)
{
    Scanner scan = new Scanner(System.in);

    System.out.print("Enter amount of distinct values: ");
    int n = scan.nextInt();

    for(int i = 0; i < n; i++)
    {
        double nRandomValues = (Math.random() * 6) + 0;

        System.out.println(nRandomValues);
    }
}

}

OldProgrammer     2015-06-18 23:26:33

Java Coder : the input data has already been generated using a random number generator. Your program needs to read it in as it did for n. The program does not need to call Math.random.

Once the double value is read in and multiplied by 6, the program needs to remove the fractional part. The suggestions are to use a function like Math.floor or a cast to int e.g. int intvalue = (int)doubleValue.

Hopefully, you can figure out the rest.

Java_Coder     2015-06-19 01:18:13

Thanks I figured out the problem, and got it correct :D

Please login and solve 5 problems to be able to post at forum