FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-programs/GuessMyNumber/guess.java at main · IntScription/java-programs · GitHub
IntScription
/
java-programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-programs
/
GuessMyNumber
/
guess.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (34 loc) · 1.06 KB
Breadcrumbs
java-programs
/
GuessMyNumber
/
guess.java
Copy path
File metadata and controls
36 lines (34 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
Build a program called “GuessMyNumber.” The computer will generate a random number between 1 and 10.
The user types in a number and the computer replies “lower” if the random number is lower than the guess,
“higher” if the random number is higher, and “correct!” if the guess is correct.
The player can continue guessing until the guess is right.
*/
package
GuessMyNumber
;
import
java
.
util
.
Random
;
import
java
.
util
.
Scanner
;
public
class
guess
{
public
static
void
main
(
String
[]
args
) {
Random
rd
=
new
Random
();
int
min
=
1
;
int
max
=
10
;
int
rnum
=
rd
.
nextInt
(
min
+
max
) +
min
;
Scanner
sc
=
new
Scanner
(
System
.
in
);
while
(
true
) {
System
.
out
.
println
(
"Enter a number between 0 to 10"
);
int
guess
=
sc
.
nextInt
();
if
(
guess
<
rnum
) {
System
.
out
.
println
(
"Your guess is lesser"
);
}
else
if
(
guess
>
rnum
) {
System
.
out
.
println
(
"Your guess is higher"
);
}
else
{
System
.
out
.
println
(
"Your guess is right"
);
break
;
}
}
System
.
out
.
println
(
"GAME OVER"
);
sc
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL