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:
Spring Boot - Admin Server
Java Program to Implement Expression Tree
The DAO with Spring and Hibernate
Java Program to Show the Duality Transformation of Line and Point
Guide to WeakHashMap in Java
Introduction to the Java NIO2 File API
Jackson – JsonMappingException (No serializer found for class)
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Guide to Spring @Autowired
Serialization và Deserialization trong java
An Intro to Spring Cloud Security
Java Program to Implement LinkedBlockingDeque API
The XOR Operator in Java
Java Program to Represent Graph Using Incidence List
Java Program to Implement Ternary Search Algorithm
Java Program to Find MST (Minimum Spanning Tree) using Kruskal’s Algorithm
ArrayList trong java
Finding Max/Min of a List or Collection
Java Program to Implement Knapsack Algorithm
Prevent Brute Force Authentication Attempts with Spring Security
Spring RestTemplate Error Handling
Predicate trong Java 8
Xử lý ngoại lệ đối với trường hợp ghi đè phương thức trong java
Generate Spring Boot REST Client with Swagger
Spring Boot - Service Components
Java Program to Check whether Undirected Graph is Connected using BFS
Hướng dẫn Java Design Pattern – Composite
Intro to the Jackson ObjectMapper
Java Web Services – JAX-WS – SOAP
Spring Boot - Servlet Filter
Intro to Spring Boot Starters
Examine the internal DNS cache