- problem 2: TestMyGame
This commit is contained in:
HeshamTB 2020-08-30 11:39:58 +03:00
parent b47513a6f3
commit 729acce78c
Signed by: Hesham
GPG Key ID: 74876157D199B09E

23
lab-0/src/TestMyGame.java Normal file
View File

@ -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