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 Bellman-Ford Algorithm
Java String Conversions
How to use the Spring FactoryBean?
Encode/Decode to/from Base64
Java Program to Check whether Graph is a Bipartite using 2 Color Algorithm
Build a REST API with Spring and Java Config
Guide to CountDownLatch in Java
Giới thiệu Json Web Token (JWT)
Java Program to Implement Ternary Search Algorithm
Serialization và Deserialization trong java
Lớp TreeMap trong Java
Java Program to Perform LU Decomposition of any Matrix
Spring Boot - Internationalization
Quick Guide to Spring Controllers
Spring Security Logout
Java Program to Implement Direct Addressing Tables
Java Program to Perform Searching Using Self-Organizing Lists
Basic Authentication with the RestTemplate
Java Program to Check whether Graph is a Bipartite using DFS
Java Program to Implement Max Heap
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Spring Cloud AWS – S3
Java Program to Implement Pollard Rho Algorithm
Giới thiệu Java Service Provider Interface (SPI) – Tạo các ứng dụng Java dễ mở rộng
Hướng dẫn Java Design Pattern – Bridge
Tính đóng gói (Encapsulation) trong java
Introduction to Spring Cloud CLI
Java Program to Solve any Linear Equation in One Variable
Java Program to Implement SynchronosQueue API
Java Program to Implement Graph Structured Stack
Immutable Map Implementations in Java
A Guide to WatchService in Java NIO2