Last active
November 30, 2016 00:38
-
-
Save JashuaCovington/e7a1ae95a6d0aedb08d6185cc2defaf7 to your computer and use it in GitHub Desktop.
Guessing Game Java Language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Java Guessing Game class. | |
* | |
* @author Jashua Covington | |
* @version 2 (June 20, 2013) | |
*/ | |
//The guess a number game | |
//randomly generate a number between 1 and 10 | |
//let user guess (hint: add error while loop to get good input data) | |
//while no correct guess //give feedback: warm or cold | |
//counts the number of guesses | |
//when user guesses, print congrats and #of guesses } | |
import java.util.Scanner; | |
import java.util.Random; | |
public class GuessingGame | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner mets = new Scanner(System.in); | |
Random randGuess = new Random(); | |
int timesGuessed =0; | |
int randNum = randGuess.nextInt(10)+1; | |
int tryGuess; | |
boolean win = false; | |
while(win == false) | |
{ | |
System.out.println("Guess a number between 1 - 10: "); | |
tryGuess = mets.nextInt(); | |
timesGuessed++; | |
if(tryGuess == randNum) | |
{ | |
win = true; | |
} | |
else if (tryGuess < randNum) | |
{ | |
System.out.println("You are getting cold!"); | |
} | |
else if (tryGuess > randNum) | |
{ | |
System.out.println("You are getting hot!"); | |
} | |
} | |
System.out.println("Congrats You guessed it!"); | |
System.out.println("Number of Times Guessed" + timesGuessed + " "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment