-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber.kt
More file actions
31 lines (25 loc) · 820 Bytes
/
Number.kt
File metadata and controls
31 lines (25 loc) · 820 Bytes
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
package example.myapp
import java.util.*
fun main(args: Array<String>) {
val min = 0
val max = 100
var nbAtmpts = 0
val random = SplittableRandom()
val reader = Scanner(System.`in`)
val goal = random.nextInt(min, max)
var usGuss: Int
computerSays("I chose a number between $min and $max")
do {
nbAtmpts++
computerSays("What's your guess?")
usGuss = reader.nextInt()
when {
usGuss > goal -> computerSays("less !")
usGuss < goal -> computerSays("more !")
usGuss == goal -> computerSays("Congratulation ! You found correct number in $nbAtmpts attempts.")
}while(usGuss != goal)
computerSays("Congratulation ! You found correct number in $nbAtmpts attempts.")
}
fun String.outputAsComputer() {
println("Computer : " + this)
}