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:
Iterable to Stream in Java
Java Program to Find the Minimum value of Binary Search Tree
Spring Boot - Tracing Micro Service Logs
Java Program to Implement Word Wrap Problem
Simultaneous Spring WebClient Calls
Java Program to Implement Adjacency List
JPA/Hibernate Persistence Context
Spring Boot Actuator
Interface trong Java 8 – Default method và Static method
Java Program to Describe the Representation of Graph using Incidence Matrix
Uploading MultipartFile with Spring RestTemplate
Mapping Nested Values with Jackson
Spring REST API + OAuth2 + Angular
Java Program to Implement Ternary Search Tree
Weak References in Java
Java Program to Implement Shunting Yard Algorithm
Bootstrapping Hibernate 5 with Spring
So sánh HashMap và HashSet trong Java
Java Program to find the number of occurrences of a given number using Binary Search approach
Partition a List in Java
Guide to Selenium with JUnit / TestNG
Jackson Date
Java Program to Implement Binomial Heap
Spring Cloud – Bootstrapping
Consuming RESTful Web Services
Using a List of Values in a JdbcTemplate IN Clause
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Java Program to Implement the linear congruential generator for Pseudo Random Number Generation
Guide to Guava Table
Spring Boot - Tomcat Deployment
New Features in Java 15
Java Program to Find the Edge Connectivity of a Graph