From a5f5340bd658a401eba44cc9a398e87f47b91aac Mon Sep 17 00:00:00 2001 From: Mahesh Giri <107906801+Codewithmahesh@users.noreply.github.com> Date: Wed, 22 Oct 2025 17:06:50 +0530 Subject: [PATCH 1/2] Create README.md for Java Random Number Generator Added a README file with project details and usage instructions. --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7df4630 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Java Random Number Generator 🎲 + +A simple Java program to pick a random number from a predefined set — now interactive for beginners! + +--- + +## 🚀 Getting Started + +1. **Clone the repo** +2. **Navigate to the project folder** +3. **Compile and run** + +--- + +## 📋 Usage Example + + +--- + +## 👩‍💻 How does it work? + +- The program shows all available numbers. +- Picks one at random each time, using Java's `Random` class. +- You can keep generating new numbers as you wish! +- Helpful comments explain each step for beginners. + +--- + +## 🌟 Contributing + +Beginner ideas for contribution: +- Add new numbers to the array, or let the user provide their own set of numbers. +- Add error handling, more input features, or run statistics. +- Enhance this README with more guides or visuals. + +### How to contribute? +1. Fork this repo +2. Make your changes +3. Push to your fork and submit a Pull Request + +All contributions welcome — big or small! + +--- From 34521bd8b329b498541b664eb5aa43c4d3bd8bbc Mon Sep 17 00:00:00 2001 From: Codewithmahesh Date: Wed, 22 Oct 2025 17:07:59 +0530 Subject: [PATCH 2/2] Enhanced random number generator and updated README --- src/Main.class | Bin 0 -> 1731 bytes src/Main.java | 29 ++++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/Main.class diff --git a/src/Main.class b/src/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..65b6fd94dae6765f70d23c9f54e6ebf84c2faa60 GIT binary patch literal 1731 zcmaJ>O;;OL7=AAKm}D4WNC}0?$DmY`@{w9KDzrtLN*hfGHk6v;*O1)8lw@u?Gbyrg zr+b$@UAS=L!j0lN!9x|#(bI+9xzJzGAJL8CdneG79yoHsd+*%$`+1*xAN{+#2jBv3 zspvpJK~O^oVFvxSdDl!;O?xd>SiQ~59z*!NWn11whCm{@97P0C1*(QlXwR4zw_K0c z$VxQGDW3BKSt7OQShiR69B$TTBj{#`EehAQR;%2w8?{yLxHE2brfg}2U~1ElAS#1?l`wn$3IM{!QWD|nS5A~WPHn=|w! zj>RX9*A={>;Z14Y#*r5MR2hwdz)53P!+B}b>4}`!+ z%nsNOv|)IUq*MbzM3F5DWuaTtVataMGqHB5&GA| zIw^ETib#k=RKHGA)#pfd>Qf{&T`lCcp~SkH=$Xh*?p+L|gYn?-HyE0X2dC2^(#1o& zhy!HsMUZ{F|Co-N7<_=C(hf%Q4=`HV#@G%{FHBDCHIYb%CgP##bXar$LV($L_BdN`h6=~m*y?6M%&!d<23IV2Kk)HetG~A(e6W#cn z-k>i@{}oks5B>O>==&W8@gq**S9+TMAVB}b2>zl=xj<121onyPAq52m@6(S4jwcxT m2LlR*6tW7S=x1KSby~ZrhGoM0LtlQ3Pw7mhZxdy34E_hMRj}Fs literal 0 HcmV?d00001 diff --git a/src/Main.java b/src/Main.java index 340a865..8c671a5 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,13 +1,32 @@ import java.util.Random; +import java.util.Scanner; public class Main { - public static void main(String args[]){ + public static void main(String[] args) { + // List of numbers to pick from + int[] numbers = {5, 4, 8, 9, 6, 3, 7, 4, 2, 85, 63, 45, 10}; + + // Show all possible numbers + System.out.print("Possible numbers: "); + for (int num : numbers) { + System.out.print(num + " "); + } + System.out.println(); - int[] numbers = new int[]{5,4,8,9,6,3,7,4,2,85,63,45,10}; Random random = new Random(); - int ranNum = random.nextInt(numbers.length-1); - int a = numbers[ranNum]; - System.out.print("Your generated random number is: " + a); + Scanner scanner = new Scanner(System.in); + + String choice; + do { + int randomIndex = random.nextInt(numbers.length); + int result = numbers[randomIndex]; + System.out.println("🎲 Your generated random number is: " + result); + + System.out.print("Do you want to generate another number? (yes/no): "); + choice = scanner.nextLine().trim().toLowerCase(); + } while (choice.equals("yes")); + System.out.println("Thank you for using the Random Number Generator!"); + scanner.close(); } }