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
1 change: 1 addition & 0 deletions BeginnersFriendlyRepositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ If you know any good repository for beginners, feel free to add it to this table
| OpenSauce | [Link](https://github.com/TechnoBlogger14o3/OpenSauce) | Multiple Languages, DSA, Algorithms |
| Awesome Lists | [Link](https://github.com/sindresorhus/awesome) | Markdown, Documentation |
| 30 Seconds of Code | [Link](https://github.com/30-seconds/30-seconds-of-code) | JavaScript, TypeScript, Python |
| Java Number Guessing Game | [Link](https://github.com/avinash201199/Hacktoberfest2025/blob/main/JavaPrograms/NumberGuessingGame.java) | Java |



Expand Down
38 changes: 38 additions & 0 deletions JavaPrograms/NumberGuessingGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Number Guessing Game
* A beginner-friendly console Java program
* Author: Madhu
*/

import java.util.Scanner;
import java.util.Random;

public class NumberGuessingGame {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random rand = new Random();

int numberToGuess = rand.nextInt(100) + 1;
int guess;
int attempts = 0;

System.out.println("🎯 Welcome to the Number Guessing Game!");
System.out.println("Guess a number between 1 and 100:");

do {
System.out.print("Your guess: ");
guess = scanner.nextInt();
attempts++;

if (guess < numberToGuess) {
System.out.println("Too low!");
} else if (guess > numberToGuess) {
System.out.println("Too high!");
} else {
System.out.println("✅ Correct! You guessed it in " + attempts + " attempts.");
}
} while (guess != numberToGuess);

scanner.close();
}
}