Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package NumberGuessingGame;
import java.util.Random;
import java.util.Scanner;

public class NumberGuessingGame {
public static void main(String[] args) {
Random random = new Random();
int actual_number = random.nextInt(100) + 1; // Number between 1 and 100
int guess = 0;
int tries = 0;

Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the Number Guessing Game!");
System.out.println("I'm thinking of a number between 1 and 100.");

while (guess != actual_number) {
System.out.print("Guess the number: ");
guess = sc.nextInt();
tries++;

if (actual_number>50 && guess > 50 && guess != actual_number) {
if (actual_number%10 == 0)
System.out.println("Hint: The number is greater than 50 and a multiple of 10.");
else
System.out.println("Hint: The number is greater than 50 but not a multiple of 10.");
if (actual_number % 2 == 0)
System.out.println("Hint: The number is even.");
else
System.out.println("Hint: The number is odd.");
if (guess < actual_number) {
System.out.println("Guess a higher number.");
} else {
System.out.println("Guess a lower number.");
}
} else if (actual_number <= 50 && guess <= 50 && guess != actual_number) {
if (actual_number % 10 == 0)
System.out.println("Hint: The number is 50 or less and a multiple of 10.");
else
System.out.println("Hint: The number is 50 or less but not a multiple of 10.");
if (actual_number % 2 == 0)
System.out.println("Hint: The number is even.");
else
System.out.println("Hint: The number is odd.");
if (guess < actual_number)
System.out.println("Guess a higher number.");
else
System.out.println("Guess a lower number.");
} else if (actual_number<=50 && guess >50 && guess != actual_number) {
if (actual_number % 10 == 0)
System.out.println("Hint: The number is 50 or less and a multiple of 10.");
else
System.out.println("Hint: The number is 50 or less but not a multiple of 10.");
if (actual_number % 2 == 0)
System.out.println("Hint: The number is even.");
else
System.out.println("Hint: The number is odd.");
if (guess < actual_number)
System.out.println("Guess a higher number.");
else
System.out.println("Guess a lower number.");
} else if (actual_number>=50 && guess <50 && guess != actual_number) {
if (actual_number%10 == 0)
System.out.println("Hint: The number is greater than 50 and a multiple of 10.");
else
System.out.println("Hint: The number is greater than 50 but not a multiple of 10.");
if (actual_number % 2 == 0)
System.out.println("Hint: The number is even.");
else
System.out.println("Hint: The number is odd.");
if (guess < actual_number) {
System.out.println("Guess a higher number.");
} else {
System.out.println("Guess a lower number.");
}
}



else
System.out.println("Wohooo! You guessed the number correctly! It was " + actual_number + ".");

}
System.out.println("You guessed it in " + tries + " tries.");
System.out.println("Thanks for playing!");
sc.close();
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
**Contributor** bigturtle679
# Number Guessing Game

This is a simple but challenging command-line Java application for a "guess the number" game. The program generates a random number between 1 and 100 and prompts the user to guess it.

What makes this game unique is its **advanced hint system**, which provides multiple clues to help the user narrow down the possibilities with each incorrect guess.

## Features

* **Random Number Generation:** Generates a new random number between 1 and 100 every time the game is played.
* **Unlimited Guesses:** Users can keep guessing until they find the correct number.
* **Attempt Counter:** The game tracks the total number of tries it takes the user to guess correctly.
* **Advanced Hint System:** For every incorrect guess, the game provides a set of detailed hints:
* **Higher/Lower:** The standard "Guess a higher
Loading