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 the Nearest Neighbor Using K-D Tree Search
Jackson Date
Introduction to Liquibase Rollback
Spring Webflux and CORS
Java Program to Generate a Random Subset by Coin Flipping
Hướng dẫn sử dụng lớp Console trong java
Class Loaders in Java
JUnit 5 @Test Annotation
Performance Difference Between save() and saveAll() in Spring Data
Java Program to Use the Bellman-Ford Algorithm to Find the Shortest Path
Java – Delete a File
Introduction to Spring Boot CLI
Registration – Password Strength and Rules
Java Program to Implement the MD5 Algorithm
Spring Cloud AWS – S3
Create a Custom Auto-Configuration with Spring Boot
Lớp HashMap trong Java
Custom Thread Pools In Java 8 Parallel Streams
Spring 5 and Servlet 4 – The PushBuilder
Java Program to Check Multiplicability of Two Matrices
Spring Cloud – Securing Services
Java Program to Perform Inorder Recursive Traversal of a Given Binary Tree
DynamoDB in a Spring Boot Application Using Spring Data
Spring Boot Integration Testing with Embedded MongoDB
Spring Boot - Logging
Java Program to Implement RoleList API
How to Add a Single Element to a Stream
Java Program to Perform LU Decomposition of any Matrix
Java Program to Implement Adjacency Matrix
Java Program to Implement an Algorithm to Find the Global min Cut in a Graph
Spring Security Logout
Java Program to Implement Lloyd’s Algorithm