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 Graph Structured Stack
Implementing a Runnable vs Extending a Thread
JUnit5 Programmatic Extension Registration with @RegisterExtension
Logging in Spring Boot
Spring Boot - Google OAuth2 Sign-In
An Intro to Spring Cloud Security
Java Program to Implement Horner Algorithm
Java Program to Permute All Letters of an Input String
Giới thiệu Google Guice – Injection, Scope
OAuth2 Remember Me with Refresh Token
A Guide to ConcurrentMap
Hướng dẫn Java Design Pattern – DAO
Introduction to Spring Data MongoDB
Java Program to Implement Fibonacci Heap
Java Program to Convert a Decimal Number to Binary Number using Stacks
Java Program to Implement CopyOnWriteArraySet API
Getting a File’s Mime Type in Java
An Example of Load Balancing with Zuul and Eureka
Java Program to Implement Sorted Doubly Linked List
A Guide to Spring Boot Admin
Guide to Guava Multimap
Java – Delete a File
Static Content in Spring WebFlux
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Java – Reader to InputStream
Java Program to Delete a Particular Node in a Tree Without Using Recursion
Quick Guide to java.lang.System
Java Program to Implement Ternary Heap
A Guide to TreeSet in Java
Collect a Java Stream to an Immutable Collection
Handle EML file with JavaMail
Returning Image/Media Data with Spring MVC