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! + +--- diff --git a/src/Main.class b/src/Main.class new file mode 100644 index 0000000..65b6fd9 Binary files /dev/null and b/src/Main.class differ 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(); } }