![Javascript Javascript](https://codepen.io/de-gif/pen/ZEzRmQO/image/large.png)
Game.java
May 15, 2016 I am trying to make it so that I can have up to 10 guesses on a number chosen by a friend using a text box (input). This is my first go around, but what im trying to have happen is once a text.
importjava.util.Random; |
importjava.util.Scanner; |
importjava.lang.System; |
/** |
* Created with IntelliJ IDEA. |
* User: fuzion |
* Date: 12/26/13 |
* Time: 10:14 AM |
* To change this template use File | Settings | File Templates. |
*/ |
publicclassGame { |
publicstaticvoidmain(String[] args){ |
System.out.println('Hello and welcome to my number guessing game.'); |
System.out.println('Pick a number: '); |
Scanner inputnum =newScanner(System.in); //This number will be the max number the player has to guess too. |
int maxnum; |
maxnum = inputnum.nextInt(); |
Random rand =newRandom(); |
int number = rand.nextInt(maxnum); |
int tries =0; //Will increase depending on how many tires it takes |
Scanner input =newScanner(System.in); |
int guess; |
boolean win =false; |
while (win false){ //This while loop false the code with in it repeat until win true |
System.out.println('Guess a number between 1 and '+ maxnum +': '); |
guess = input.nextInt(); |
tries++; //Increasing the number set in the variable tries by 1 |
if (guess number){ |
win =true; //Since the number is correct win true then ending the loop |
//First thing the guess is compared too |
} |
elseif(guess < number){ |
System.out.println('Number is to low, tray again'); |
//2nd thing guess is compared too. |
} |
elseif(guess > number){ |
System.out.println('Number is to high, try again'); |
//3rd thing guess is compared too. |
} |
} |
System.out.println('You win!'); |
System.out.println('It took you '+ tries +' tries.'); |
} |
} |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment