Java Program to Emulate N Dice Roller

This is the java program for emulating N dice roller. This can be achieved using random numbers. User can also select how many dice in a game.

Here is the source code of the Java Program to Emulate N Dice Roller. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

//This is a sample program to emulate n dice roller
import java.util.Random;
import java.util.Scanner;
 
 
public class Emulation_N_Dice 
{
    public static void main(String args[])
    {
        System.out.println("Enter the number of dice: ");
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Random rand = new Random();
        do 
        {
            System.out.println("The values on dice are: ");
            for(int i=0; i<n; i++)
                System.out.println(rand.nextInt(6)+1);
 
            System.out.println("Continue: true/false");
        } while (sc.nextBoolean() == true);
        sc.close();
    }
}

Output:

$ javac Emulate_N_Dice.java
$ java Emulate_N_Dice
Enter the number of dice: 
6
The values on dice are: 
1 1 1 2 2 6
Continue: true/false
true
The values on dice are: 
6 5 2 5 5 1
Continue: true/false
false

Related posts:

Java Program to Find MST (Minimum Spanning Tree) using Kruskal’s Algorithm
Convert String to int or Integer in Java
Validations for Enum Types
Java Program to Implement CopyOnWriteArrayList API
Java Program to Perform Searching Based on Locality of Reference
Java Program to implement Array Deque
Luồng Daemon (Daemon Thread) trong Java
Quick Guide to @RestClientTest in Spring Boot
Java Program to Implement Park-Miller Random Number Generation Algorithm
Consuming RESTful Web Services
Spring Data – CrudRepository save() Method
Giới thiệu Design Patterns
Java Program to Implement Quick Sort with Given Complexity Constraint
Java Program to Implement Dijkstra’s Algorithm using Set
Examine the internal DNS cache
Introduction to Spring Cloud OpenFeign
Java Program to Solve TSP Using Minimum Spanning Trees
Generate Spring Boot REST Client with Swagger
Java Program to Implement Euler Circuit Problem
Java Program to Implement Heap’s Algorithm for Permutation of N Numbers
Java Program to Implement Max-Flow Min-Cut Theorem
Injecting Prototype Beans into a Singleton Instance in Spring
Guide to java.util.concurrent.BlockingQueue
Java Program to Check whether Directed Graph is Connected using DFS
Java Program to Implement Double Ended Queue
Java Program to Solve a Matching Problem for a Given Specific Case
Object Type Casting in Java
Java Program to Perform Matrix Multiplication
Using a Spring Cloud App Starter
Java Program to Implement Variable length array
Java Program to Implement the MD5 Algorithm
Java Program to Implement the Monoalphabetic Cypher