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:
JUnit5 @RunWith
Custom Error Pages with Spring MVC
Merging Streams in Java
Java Program to Find the Edge Connectivity of a Graph
Comparing Two HashMaps in Java
Java Program to Check Cycle in a Graph using Graph traversal
Giới thiệu Design Patterns
Quick Guide to Spring Bean Scopes
Tìm hiểu cơ chế Lazy Evaluation của Stream trong Java 8
Chuyển đổi giữa các kiểu dữ liệu trong Java
Configuring a DataSource Programmatically in Spring Boot
An Introduction to ThreadLocal in Java
Spring Boot Tutorial – Bootstrap a Simple Application
Sorting in Java
Read an Outlook MSG file
Spring Boot: Customize Whitelabel Error Page
Java Deep Learning Essentials - Yusuke Sugomori
Java – Reader to Byte Array
Java Program to Implement Shell Sort
Java Program to do a Depth First Search/Traversal on a graph non-recursively
Spring Boot - Sending Email
Java Program to Implement a Binary Search Algorithm for a Specific Search Sequence
The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5
Java Program to Generate N Number of Passwords of Length M Each
Java Program to Implement Gale Shapley Algorithm
Java Program to Implement Euclid GCD Algorithm
Tips for dealing with HTTP-related problems
Converting Strings to Enums in Java
Java Program to Perform Sorting Using B-Tree
Java equals() and hashCode() Contracts
Hướng dẫn Java Design Pattern – Memento
Refactoring Design Pattern với tính năng mới trong Java 8