initial commit
This commit is contained in:
33
src/main/java/tech/nevets/numberguesser/Game.java
Normal file
33
src/main/java/tech/nevets/numberguesser/Game.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package tech.nevets.numberguesser;
|
||||
|
||||
import java.sql.SQLOutput;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Game {
|
||||
public static void main(String[] args) {
|
||||
Random rand = new Random();
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int randNum = rand.nextInt(100) + 1;
|
||||
int tryCount = 0;
|
||||
|
||||
while (true) {
|
||||
System.out.println("Enter your guess (1-100): ");
|
||||
|
||||
int playerGuess = scanner.nextInt();
|
||||
tryCount++;
|
||||
|
||||
if (playerGuess == randNum) {
|
||||
System.out.println("Correct! You win!");
|
||||
System.out.println("Took you " + tryCount + " tries!");
|
||||
break;
|
||||
} else if (randNum > playerGuess) {
|
||||
System.out.println("Nope, number is higher");
|
||||
} else {
|
||||
System.out.println("Nope, number is lower");
|
||||
}
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user