Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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!

---
Binary file added src/Main.class
Binary file not shown.
29 changes: 24 additions & 5 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}