Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Setting up The game
- //First make a new JavaProject
- //Then go to src and right click on it then go to new then go to class make sure its public static void main(String[] args) {
- //Then put this code and enjoy:)
- //if you made new things and you want to debug it go to int randomNumber = rand.nextInt(100) + 1 ; and make a new line under it and put
- //System.out.println("The number is " + randomNumber);
- // to play Hit ctrl+11 annd play in the console, Enjoy:)
- //Also if you want to make the player can guess 10times only then put a code under int randomNumber = rand.nextInt(100) + 1 ;
- //Then put this code for (int i = 0; i <10; i++) { put the other "}" at the last line make sure when u put it remove while(true) { and
- //the other "}" at the last line
- import java.util.Random;
- import java.util.Scanner;
- public class NumberGuessingGame {
- public static void main(String[] args) {
- Random rand = new Random();
- int randomNumber = rand.nextInt(100) + 1;
- while(true) {
- System.out.println("Enter your guess(1-100):");
- Scanner scanner = new Scanner(System.in);
- int playerGuess = scanner.nextInt();
- if (playerGuess == randomNumber) {
- System.out.println("Correct! You Won!");
- break;
- }
- else if (randomNumber > playerGuess) {
- System.out.println("False.. The number is higher. Guess again");
- }
- else {
- System.out.println("False.. The number is lower. Guess again:");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment