From 1e6efb250af36481b7e0cc74864e5734d0c95151 Mon Sep 17 00:00:00 2001 From: Gurraj Singh <147290984+Gurraj855@users.noreply.github.com> Date: Sun, 15 Oct 2023 05:06:26 -0500 Subject: [PATCH 1/2] Create Dice2.java --- Dice2.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Dice2.java diff --git a/Dice2.java b/Dice2.java new file mode 100644 index 0000000..7182b78 --- /dev/null +++ b/Dice2.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. + + + + + From d2df9448a348d4aa42674a08e6c81a6a27949d8f Mon Sep 17 00:00:00 2001 From: Hvardhan2 <147965075+Hvardhan2@users.noreply.github.com> Date: Sun, 15 Oct 2023 05:12:19 -0500 Subject: [PATCH 2/2] Create calculate factorial --- calculate factorial | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 calculate factorial diff --git a/calculate factorial b/calculate factorial new file mode 100644 index 0000000..ffc52e9 --- /dev/null +++ b/calculate factorial @@ -0,0 +1,17 @@ +public class FactorialCalculator { + public static void main(String[] args) { + int number = 5; // Change this to the desired number + long factorial = calculateFactorial(number); + System.out.println("Factorial of " + number + " is " + factorial); + } + + public static long calculateFactorial(int n) { + if (n < 0) { + throw new IllegalArgumentException("Input must be a non-negative integer"); + } + if (n == 0) { + return 1; + } + return n * calculateFactorial(n - 1); + } +}