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 Perform Arithmetic Operations on Numbers of Size
So sánh ArrayList và Vector trong Java
Loại bỏ các phần tử trùng trong một ArrayList như thế nào?
Spring Boot Integration Testing with Embedded MongoDB
Java Program to Permute All Letters of an Input String
Java – Generate Random String
Sorting in Java
Java Program for Topological Sorting in Graphs
Spring Cloud – Bootstrapping
Spring Boot - Batch Service
Spring Data JPA @Modifying Annotation
Spring Cloud – Tracing Services with Zipkin
Java 8 – Powerful Comparison with Lambdas
Introduction to Spring Data JDBC
Java Program to Find kth Largest Element in a Sequence
Spring REST with a Zuul Proxy
Java Program to Implement ConcurrentSkipListMap API
Java Program to find the maximum subarray sum using Binary Search approach
Using Java Assertions
Java Program to Implement Disjoint Set Data Structure
Spring Security Form Login
Introduction to Spring Boot CLI
Java Program to Implement vector
Một số nguyên tắc, định luật trong lập trình
Send an email with an attachment
MyBatis with Spring
Jackson Annotation Examples
Comparing Arrays in Java
How To Serialize and Deserialize Enums with Jackson
Spring Boot with Multiple SQL Import Files
Introduction to Spring Cloud Netflix – Eureka
Giới thiệu luồng vào ra (I/O) trong Java