forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuessNumber.java
45 lines (29 loc) · 1000 Bytes
/
GuessNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.company;
import java.util.Random;
import java.util.Scanner;
public class GuessNumber
{
public static void main(String[] args) {
System.out.printf("***Welcome Guess Number game ****\n");
Random ra = new Random();
int gen = ra.nextInt(10);
System.out.printf("Guess ? \n");
int number ;
System.out.printf("Enter the number to guess between 0 to 9 \n");
Scanner scan = new Scanner(System.in);
number = scan.nextInt();
do {
if (number>gen)
{
System.out.printf("Please try again Number %d > ? \n",number);
number = scan.nextInt();
}
else
{
System.out.printf("Please try again Number %d < ? \n",number);
number = scan.nextInt();
}
}while ( number!=gen);
System.out.println("Great you won " + " number is " + gen );
}
}