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 LinkedTransferQueue API
Sorting in Java
Count Occurrences of a Char in a String
Spring Boot: Customize the Jackson ObjectMapper
Java Program to Implement Warshall Algorithm
Java Program to find the number of occurrences of a given number using Binary Search approach
Java Program to Implement the Vigenere Cypher
Java Program to Solve any Linear Equation in One Variable
Xử lý ngoại lệ trong Java (Exception Handling)
Collect a Java Stream to an Immutable Collection
Custom Thread Pools In Java 8 Parallel Streams
Java Program to Find kth Largest Element in a Sequence
Java Program to Implement Shunting Yard Algorithm
REST Pagination in Spring
Java Program to Implement Interval Tree
Java Program to Implement Dijkstra’s Algorithm using Priority Queue
Java Program to Implement Sorted Array
Java Program to Find Nearest Neighbor for Static Data Set
Bootstrapping Hibernate 5 with Spring
Java Program to Implement Bubble Sort
JPA/Hibernate Persistence Context
Java Program to Implement Bit Array
Java Program to Check Whether a Directed Graph Contains a Eulerian Cycle
Ignore Null Fields with Jackson
Xây dựng ứng dụng Client-Server với Socket trong Java
Receive email using POP3
Hướng dẫn Java Design Pattern – DAO
Java Program to Perform String Matching Using String Library
Spring Cloud AWS – S3
SOAP Web service: Upload và Download file sử dụng MTOM trong JAX-WS
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Java Program to Check if it is a Sparse Matrix