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:
Comparing Objects in Java
A Guide to the ViewResolver in Spring MVC
Thực thi nhiều tác vụ cùng lúc như thế nào trong Java?
Spring RestTemplate Request/Response Logging
LinkedHashSet trong Java hoạt động như thế nào?
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Java Program to Implement Regular Falsi Algorithm
String Processing with Apache Commons Lang 3
Giới thiệu Design Patterns
Introduction to Eclipse Collections
Java Program to Generate All Possible Combinations of a Given List of Numbers
Class Loaders in Java
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Constructor Dependency Injection in Spring
Converting Strings to Enums in Java
Difference Between Wait and Sleep in Java
Instance Profile Credentials using Spring Cloud
Spring REST API + OAuth2 + Angular
Spring MVC Async vs Spring WebFlux
Entity To DTO Conversion for a Spring REST API
Java Program to Check Whether a Weak Link i.e. Articulation Vertex Exists in a Graph
Dockerizing a Spring Boot Application
Java Program to Find the Shortest Path from Source Vertex to All Other Vertices in Linear Time
Sorting in Java
Reading an HTTP Response Body as a String in Java
Giới thiệu java.io.tmpdir
Using Java Assertions
Default Password Encoder in Spring Security 5
Set Interface trong Java
Spring Boot - Rest Controller Unit Test
Phương thức forEach() trong java 8
Spring REST API + OAuth2 + Angular (using the Spring Security OAuth legacy stack)