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:
Introduction to Spring Cloud OpenFeign
Get the workstation name or IP
Java Program to Implement Tarjan Algorithm
What is a POJO Class?
Spring Boot - Twilio
Running Spring Boot Applications With Minikube
Spring Boot - Zuul Proxy Server and Routing
Java Program to Solve Travelling Salesman Problem for Unweighted Graph
The Spring @Controller and @RestController Annotations
Java Program to Perform Encoding of a Message Using Matrix Multiplication
Daemon Threads in Java
Guide to CountDownLatch in Java
Java Program to Implement Bubble Sort
Spring Cloud – Adding Angular
Weak References in Java
Spring NoSuchBeanDefinitionException
Predicate trong Java 8
Bootstrapping Hibernate 5 with Spring
Reversing a Linked List in Java
Java Program to Find the Vertex Connectivity of a Graph
Instance Profile Credentials using Spring Cloud
Jackson – Change Name of Field
Shuffling Collections In Java
Java Program to Implement Variable length array
Java Program to Implement Shoelace Algorithm
Java Program to Implement Ternary Heap
Java Program to Perform the Sorting Using Counting Sort
Optional trong Java 8
The Thread.join() Method in Java
Error Handling for REST with Spring
The Java 8 Stream API Tutorial
List Interface trong Java