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:
Autoboxing và Unboxing trong Java
Using Spring ResponseEntity to Manipulate the HTTP Response
Allow user:password in URL
Extract network card address
The Registration Process With Spring Security
Spring Boot - Rest Controller Unit Test
Sử dụng Fork/Join Framework với ForkJoinPool trong Java
Join and Split Arrays and Collections in Java
Mockito and JUnit 5 – Using ExtendWith
Java Program to Describe the Representation of Graph using Adjacency List
Java – Random Long, Float, Integer and Double
Spring Web Annotations
LinkedHashSet trong Java hoạt động như thế nào?
Java Program to implement Circular Buffer
Java Program to Implement HashSet API
Java Program to Check the Connectivity of Graph Using BFS
Hướng dẫn kết nối cơ sở dữ liệu với Java JDBC
Hướng dẫn Java Design Pattern – Decorator
Java Program to Implement Singly Linked List
Java Program to Implement Regular Falsi Algorithm
Chương trình Java đầu tiên
Java Program to Perform the Shaker Sort
Java Program to Implement AA Tree
Hướng dẫn Java Design Pattern – Null Object
Summing Numbers with Java Streams
Vấn đề Nhà sản xuất (Producer) – Người tiêu dùng (Consumer) và đồng bộ hóa các luồng trong Java
HttpClient Basic Authentication
Hướng dẫn Java Design Pattern – Dependency Injection
Java Program to Implement Depth-limited Search
Java Program to Implement Disjoint Set Data Structure
Quick Guide to @RestClientTest in Spring Boot
Java Program to Implement Meldable Heap