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:
Spring Data MongoDB – Indexes, Annotations and Converters
Java Program to Implement Interpolation Search Algorithm
Java Program to Find Strongly Connected Components in Graphs
Hướng dẫn Java Design Pattern – Command
Spring Boot - Build Systems
Java Program to Implement Quick Sort Using Randomization
Java Program to Perform Left Rotation on a Binary Search Tree
New Features in Java 8
Injecting Prototype Beans into a Singleton Instance in Spring
Java Program to implement Priority Queue
Java Program to Implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for Elements Fro...
Hướng dẫn Java Design Pattern – Template Method
Spring 5 WebClient
Jackson Unmarshalling JSON with Unknown Properties
Hướng dẫn Java Design Pattern – Transfer Object
Java Program to Represent Graph Using Adjacency List
Java Program to Implement Patricia Trie
Java Program to Implement Skew Heap
Remove All Occurrences of a Specific Value from a List
Spring Cloud AWS – S3
Java Program to Implement LinkedBlockingDeque API
A Guide to Queries in Spring Data MongoDB
Java Program to Perform Preorder Non-Recursive Traversal of a Given Binary Tree
Java Program to Implement Meldable Heap
Guide to Guava Table
Java Program to do a Breadth First Search/Traversal on a graph non-recursively
Java Program to Find the Edge Connectivity of a Graph
Get the workstation name or IP
Finding the Differences Between Two Lists in Java
Recommended Package Structure of a Spring Boot Project
Java Program to Find the Number of Ways to Write a Number as the Sum of Numbers Smaller than Itself
Java Program to Check whether Graph is Biconnected