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:
Refactoring Design Pattern với tính năng mới trong Java 8
Spring Boot - File Handling
Send an email using the SMTP protocol
Guide to PriorityBlockingQueue in Java
Java Program to Implement Binomial Heap
Java Program to Implement the Monoalphabetic Cypher
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Java Collections Interview Questions
Servlet 3 Async Support with Spring MVC and Spring Security
Most commonly used String methods in Java
Spring Boot With H2 Database
HttpAsyncClient Tutorial
Hướng dẫn Java Design Pattern – Iterator
Các kiểu dữ liệu trong java
Spring Boot - Exception Handling
Working with Network Interfaces in Java
A Guide to the ViewResolver in Spring MVC
Java Program to Find the Number of Ways to Write a Number as the Sum of Numbers Smaller than Itself
Hướng dẫn Java Design Pattern – Bridge
Receive email by java client
Spring REST API + OAuth2 + Angular
Daemon Threads in Java
Java 8 StringJoiner
Spring Boot - Actuator
Hướng dẫn Java Design Pattern – Flyweight
Lập trình hướng đối tượng (OOPs) trong java
Java Byte Array to InputStream
Java Program to Implement Cubic convergence 1/pi Algorithm
Guide To CompletableFuture
Checked and Unchecked Exceptions in Java
Java 8 – Powerful Comparison with Lambdas
Java Program to Solve a Matching Problem for a Given Specific Case