Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String args[]) {
- playGame();
- }
- public static int randomNumber() {
- int range = 100;
- int randomNumber = (int) (Math.random() * range);
- System.out.println(randomNumber);
- return randomNumber;
- }
- public static void playGame() {
- int computerNumber = randomNumber();
- Scanner scanner = new Scanner(System.in);
- boolean win = false;
- for (int count = 0; count < 10; count++) {
- System.out.print("Choose your number\n");
- int userNumber = scanner.nextInt();
- if (userNumber == computerNumber) {
- System.out.println("win");
- win = true;
- break;
- }
- else if (userNumber < computerNumber) {
- System.out.println("Your number <");
- }
- else {
- System.out.println("Your number >");
- }
- }
- if (!win){
- System.out.println("lose");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement