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 9 Stream API Improvements
Introduction to Java Serialization
Ways to Iterate Over a List in Java
Spring Security Basic Authentication
Spring Boot - Batch Service
The XOR Operator in Java
Java Program to Implement ConcurrentLinkedQueue API
The Guide to RestTemplate
The Dining Philosophers Problem in Java
Reactive Flow with MongoDB, Kotlin, and Spring WebFlux
Server-Sent Events in Spring
Spring Boot Configuration with Jasypt
Java Optional as Return Type
Java Program to Use Above Below Primitive to Test Whether Two Lines Intersect
Java Program to Implement the Hill Cypher
Intro to Spring Boot Starters
TreeSet và sử dụng Comparable, Comparator trong java
ETL with Spring Cloud Data Flow
How to Change the Default Port in Spring Boot
Java Program to Perform Finite State Automaton based Search
Using Optional with Jackson
Java Program to Implement Iterative Deepening
Easy Ways to Write a Java InputStream to an OutputStream
Request Method Not Supported (405) in Spring
Java Program to implement Dynamic Array
Send an email with an attachment
A Guide To UDP In Java
Exception Handling in Java
Java Program to Implement Stack
Biến trong java
Guide to the Volatile Keyword in Java
How to Use if/else Logic in Java 8 Streams