From dc5f2e110025314f859aa9f4df7140b879105417 Mon Sep 17 00:00:00 2001 From: tanishhh2077 <114720156+tanishhh2077@users.noreply.github.com> Date: Sun, 15 Oct 2023 05:03:16 -0500 Subject: [PATCH] Create Dice.java --- Dice.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Dice.java diff --git a/Dice.java b/Dice.java new file mode 100644 index 0000000..7182b78 --- /dev/null +++ b/Dice.java @@ -0,0 +1,25 @@ +import java.util.Random; + +public class DiceRoller { + public static void main(String[] args) { + Random random = new Random(); + + // Simulate rolling two dice + int die1 = random.nextInt(6) + 1; // Random number between 1 and 6 for first die + int die2 = random.nextInt(6) + 1; // Random number between 1 and 6 for second die + + System.out.println("First die: " + die1); + System.out.println("Second die: " + die2); + + int total = die1 + die2; + System.out.println("Total: " + total); + } +} +In this code, the Random class is used to generate random numbers. nextInt(6) generates random integers from 0 to 5, and by adding 1, it becomes a random number from 1 to 6, which is suitable for a six-sided die. + +When you run this code, it will simulate rolling two dice and display the individual values of each die as well as their total. Each time you run the program, you will get different random numbers. + + + + +