Lab 0:
- problem 2: TestMyGame
This commit is contained in:
parent
b47513a6f3
commit
729acce78c
23
lab-0/src/TestMyGame.java
Normal file
23
lab-0/src/TestMyGame.java
Normal 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
|
Loading…
Reference in New Issue
Block a user