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:
Guide to System.gc()
Java Program to Perform Searching Based on Locality of Reference
Java Program to Implement Uniform-Cost Search
Giới thiệu Swagger – Công cụ document cho RESTfull APIs
Spring Boot: Customize Whitelabel Error Page
Java Program to Check if a Given Binary Tree is an AVL Tree or Not
Java Program to Implement Dijkstra’s Algorithm using Set
Giới thiệu Aspect Oriented Programming (AOP)
Spring JDBC
Spring Boot: Customize the Jackson ObjectMapper
Quick Guide on Loading Initial Data with Spring Boot
Java Switch Statement
Base64 encoding và decoding trong Java 8
Java Program to Implement String Matching Using Vectors
Java – Convert File to InputStream
Chuyển đổi giữa các kiểu dữ liệu trong Java
Reversing a Linked List in Java
Java Program to Implement Bit Array
TreeSet và sử dụng Comparable, Comparator trong java
Spring Boot - Batch Service
Java Program to Implement Max Heap
Java Program to Construct an Expression Tree for an Infix Expression
Spring Boot - Tomcat Port Number
Quick Guide to java.lang.System
Java Program to Find the Edge Connectivity of a Graph
Hướng dẫn Java Design Pattern – Template Method
Spring Autowiring of Generic Types
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Java Program to Perform Uniform Binary Search
How to Round a Number to N Decimal Places in Java
Spring Boot - Web Socket
Hướng dẫn Java Design Pattern – Transfer Object