initial commit

This commit is contained in:
2022-02-25 10:00:09 -05:00
commit 3bc4567a60
37 changed files with 396 additions and 0 deletions

View 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();
}
}