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 Implement Hash Tables with Double Hashing
Các chương trình minh họa sử dụng Cấu trúc điều khiển trong Java
Spring Data Reactive Repositories with MongoDB
OAuth 2.0 Resource Server With Spring Security 5
Java Program to Implement Min Heap
Connect through a Proxy
The Spring @Controller and @RestController Annotations
OAuth2 for a Spring REST API – Handle the Refresh Token in AngularJS
Servlet 3 Async Support with Spring MVC and Spring Security
Java Program to Implement Merge Sort Algorithm on Linked List
Guide to Java 8’s Collectors
LinkedHashSet trong Java hoạt động như thế nào?
Spring’s RequestBody and ResponseBody Annotations
Java Program to Implement Coppersmith Freivald’s Algorithm
Queue và PriorityQueue trong Java
Java Program to Optimize Wire Length in Electrical Circuit
REST Pagination in Spring
How to Get All Dates Between Two Dates?
Java Program to Implement Queue using Linked List
Java Program to Find Shortest Path Between All Vertices Using Floyd-Warshall’s Algorithm
So sánh ArrayList và LinkedList trong Java
Shuffling Collections In Java
Java Program to Implement Queue using Two Stacks
Weak References in Java
Java Program to Implement ConcurrentSkipListMap API
Java Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree
Serve Static Resources with Spring
Guide to ThreadLocalRandom in Java
Generating Random Numbers in a Range in Java
Phương thức forEach() trong java 8
Java String to InputStream
Java Program to Implement Horner Algorithm