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 Flood Fill Algorithm
How to Read HTTP Headers in Spring REST Controllers
Spring Boot - Google OAuth2 Sign-In
Guide to the ConcurrentSkipListMap
Guide to WeakHashMap in Java
The Spring @Controller and @RestController Annotations
Java Program to Generate All Possible Combinations Out of a, b, c, d, e
Map to String Conversion in Java
Lớp HashMap trong Java
Debug a HttpURLConnection problem
Truyền giá trị và tham chiếu trong java
Java Program to Implement Repeated Squaring Algorithm
So sánh Array và ArrayList trong Java
Java Program to Implement Sorted Doubly Linked List
Class Loaders in Java
Phương thức forEach() trong java 8
Stack Memory and Heap Space in Java
Java Program to Implement Strassen Algorithm
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Spring Data JPA and Null Parameters
Custom Cascading in Spring Data MongoDB
Java Program to implement Sparse Vector
Set Interface trong Java
Summing Numbers with Java Streams
Java Program to Convert a Decimal Number to Binary Number using Stacks
Java 8 Streams peek() API
Java Program to Implement Binary Tree
The “final” Keyword in Java
More Jackson Annotations
Simultaneous Spring WebClient Calls
Java Program to Implement CopyOnWriteArrayList API
Java Program to Implement Fibonacci Heap