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:
Debug a HttpURLConnection problem
Default Password Encoder in Spring Security 5
Java Program to Implement Min Heap
Predicate trong Java 8
Instance Profile Credentials using Spring Cloud
Java Program to Implement Self organizing List
Java Timer
Java Program to Implement Selection Sort
Spring Boot - Code Structure
Case-Insensitive String Matching in Java
Circular Dependencies in Spring
Java Program to Generate a Sequence of N Characters for a Given Specific Case
Một số nguyên tắc, định luật trong lập trình
Giới thiệu Java 8
Java Program to Show the Duality Transformation of Line and Point
Java Program to Implement Queue
Java Program to Implement Solovay Strassen Primality Test Algorithm
Java Program to Implement the Schonhage-Strassen Algorithm for Multiplication of Two Numbers
Java Program to Implement Binary Search Tree
How to Read HTTP Headers in Spring REST Controllers
Comparing Two HashMaps in Java
Receive email by java client
Tips for dealing with HTTP-related problems
Creating a Web Application with Spring 5
Connect through a Proxy
Java Program to Generate Random Numbers Using Probability Distribution Function
Java Program to Generate N Number of Passwords of Length M Each
Java Program to add two large numbers using Linked List
HashMap trong Java hoạt động như thế nào?
Java Program to Find the Minimum value of Binary Search Tree
Spring Boot - Tomcat Port Number
Spring Boot - Logging