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 Represent Graph Using Linked List
Extract network card address
Java Program to Implement Merge Sort Algorithm on Linked List
Java Program to Perform Arithmetic Operations on Numbers of Size
Java Program to Solve any Linear Equation in One Variable
Send an email with an attachment
Hướng dẫn Java Design Pattern – MVC
XML-Based Injection in Spring
Java Program to Implement Horner Algorithm
How to Replace Many if Statements in Java
Java – Reader to InputStream
Xử lý ngoại lệ trong Java (Exception Handling)
Read an Outlook MSG file
Guide to Spring Cloud Kubernetes
Java Program to Implement Trie
Custom JUnit 4 Test Runners
Send an email using the SMTP protocol
Extract links from an HTML page
Spring 5 WebClient
Remove HTML tags from a file to extract only the TEXT
Query Entities by Dates and Times with Spring Data JPA
Java Program to Implement TreeSet API
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Java Program to Check if a Directed Graph is a Tree or Not Using DFS
Java Program to Perform Searching Using Self-Organizing Lists
Java Multi-line String
Marker Interface trong Java
Handling URL Encoded Form Data in Spring REST
Why String is Immutable in Java?
Java Program to Implement the Edmond’s Algorithm for Maximum Cardinality Matching
Spring Boot - Admin Client
Validate email address exists or not by Java Code