From 729acce78c73054245bdce35c3af19df411ebac9 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 30 Aug 2020 11:39:58 +0300 Subject: [PATCH] Lab 0: - problem 2: TestMyGame --- lab-0/src/TestMyGame.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lab-0/src/TestMyGame.java diff --git a/lab-0/src/TestMyGame.java b/lab-0/src/TestMyGame.java new file mode 100644 index 0000000..a3dec8d --- /dev/null +++ b/lab-0/src/TestMyGame.java @@ -0,0 +1,23 @@ +import java.util.Random; +import java.util.Scanner; + +public class TestMyGame { + public static void main(String args[]){ + + Random rand = new Random(); + Scanner input = new Scanner(System.in); + + int guess = 0, chances = 0; + int randomValue = rand.nextInt(15) + 1; + + while (guess != randomValue){ + System.out.print("Guess any numeric value from 1 to 15 "); + guess = input.nextInt(); + chances++; + } // End while loop + + System.out.println("You won after " + chances + " try/tries"); + + } //End of main method + +} //End of TestMyGame class