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:
Registration – Password Strength and Rules
Java Program to Implement String Matching Using Vectors
Apache Commons Collections Bag
Spring Boot Integration Testing with Embedded MongoDB
Spring Boot - Web Socket
Sao chép các phần tử của một mảng sang mảng khác như thế nào?
Java equals() and hashCode() Contracts
Guava – Join and Split Collections
Java Program to Implement Gift Wrapping Algorithm in Two Dimensions
A Guide to WatchService in Java NIO2
Guide To CompletableFuture
Java Program to Implement Levenshtein Distance Computing Algorithm
Rate Limiting in Spring Cloud Netflix Zuul
Convert Hex to ASCII in Java
Loại bỏ các phần tử trùng trong một ArrayList như thế nào trong Java 8?
Java Program to Perform Right Rotation on a Binary Search Tree
Java Program to Implement Triply Linked List
Java Program to Implement Affine Cipher
Quick Guide to Spring Bean Scopes
Introduction to Spring Cloud OpenFeign
Jackson – Unmarshall to Collection/Array
Map Interface trong java
Spring Boot Tutorial – Bootstrap a Simple Application
Compare Two JSON Objects with Jackson
Using a Spring Cloud App Starter
Java Program to Generate a Random Subset by Coin Flipping
How to Manually Authenticate User with Spring Security
Check If Two Lists are Equal in Java
Running Spring Boot Applications With Minikube
Java – Create a File
Java – Combine Multiple Collections
Tính đóng gói (Encapsulation) trong java