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:
Hướng dẫn sử dụng Java Annotation
Java Program to Implement Trie
Tổng quan về ngôn ngữ lập trình java
Send email with authentication
Java Program to Implement LinkedBlockingDeque API
String Initialization in Java
Removing all duplicates from a List in Java
Exploring the New Spring Cloud Gateway
Câu lệnh điều khiển vòng lặp trong Java (break, continue)
Java Program to Generate All Subsets of a Given Set in the Gray Code Order
Lập trình đa luồng với CompletableFuture trong Java 8
Difference Between Wait and Sleep in Java
Java Program to Implement Floyd Cycle Algorithm
Concurrent Test Execution in Spring 5
Hướng dẫn Java Design Pattern – Singleton
Java Program to implement Bit Matrix
Using the Not Operator in If Conditions in Java
Java Program to Implement Stack using Two Queues
Java Program to Find Basis and Dimension of a Matrix
Spring Boot - Building RESTful Web Services
Auditing with JPA, Hibernate, and Spring Data JPA
Java 8 StringJoiner
Java Program to Implement CopyOnWriteArrayList API
REST Web service: Upload và Download file với Jersey 2.x
Java Program to Implement Pagoda
How to Get All Dates Between Two Dates?
Java Program to Implement Direct Addressing Tables
Injecting Prototype Beans into a Singleton Instance in Spring
Deploy a Spring Boot WAR into a Tomcat Server
Java Program to Implement TreeSet API
Java Program to Implement Affine Cipher
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays