Created
August 29, 2015 10:14
-
-
Save mick001/4a34ae895a7dee8ab166 to your computer and use it in GitHub Desktop.
Two simple Java programs. Full article at http://www.firsttimeprogrammer.blogspot.com/2015/03/two-simple-java-programs.html
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
import java.util.Scanner; | |
import java.util.Random; | |
public class GuessNumberMain | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println("Guess the number beween 0 and 99"); | |
Scanner reader = new Scanner(System.in); | |
int number = reader.nextInt(); | |
Random randomGenerator = new Random(); | |
int toGuess = randomGenerator.nextInt(100); | |
while(number != toGuess) | |
{ | |
if(number < toGuess) | |
{ | |
System.out.println("Higher"); | |
}else if(number > toGuess) | |
{ | |
System.out.println("Lower"); | |
} | |
System.out.println("Try again!"); | |
number = reader.nextInt(); | |
} | |
System.out.println("Congrats! You guessed it! It was: "+number); | |
reader.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice :D