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 Merge Sort on n Numbers Without tail-recursion
Java Program to Implement Euler Circuit Problem
Exploring the Spring Boot TestRestTemplate
Java InputStream to String
Guava – Join and Split Collections
Tính đóng gói (Encapsulation) trong java
Java Program to Implement Best-First Search
Introduction to Apache Commons Text
The Dining Philosophers Problem in Java
Working With Maps Using Streams
Spring’s RequestBody and ResponseBody Annotations
Generate Spring Boot REST Client with Swagger
Spring Boot - Eureka Server
Java Program to Check Whether a Weak Link i.e. Articulation Vertex Exists in a Graph
Java Program to Implement WeakHashMap API
The Registration API becomes RESTful
Spring Security and OpenID Connect
Introduction to Spring Cloud OpenFeign
Custom Exception trong Java
An Intro to Spring Cloud Vault
Get and Post Lists of Objects with RestTemplate
HttpClient 4 – Follow Redirects for POST
Check If a File or Directory Exists in Java
Guide to Java OutputStream
Java Program to Implement RenderingHints API
Spring @RequestParam Annotation
Java Program to Check Multiplicability of Two Matrices
An Intro to Spring Cloud Security
Java String to InputStream
Spring Cloud – Tracing Services with Zipkin
Guide to the Volatile Keyword in Java
Java Program to Implement HashTable API