hi_lo - and 100"); number = rand.nextInt(100) + 1;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/*'High - Low' game: 7 guess max. * ********************************/ public class hi_lo { public static void main (String [] args) { // create variables to hold data and help with processing int number, guess, countguesses; int game = 0, wins = 0; boolean done; char answer; // create objects for a random number generation and input Random rand new Random(); Scanner Keyboard = new scanner(System.in); // for as long as the user wants to play do { System.out.println("try to guess a number between 1
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: and 100"); number = rand.nextInt(100) + 1; games = games + 1; countguesses = 0; done = false; while (countguesses > 6 && !done) // ! = not, so not done = !done. countguesses less than six and not done playing. { System.out.print("guess" + countguesses + ": "); guess = keyboard.nextInt(); if (guess < number) System.out.println("too low") else if (guess > number) System.out.println("too high"); else /* guess == number */ { wins = wins + 1;...
View Full Document

This note was uploaded on 04/03/2010 for the course COMPSCI 600.107 taught by Professor Houlahan during the Spring '08 term at Johns Hopkins.

Ask a homework question - tutors are online