Guess until you get it right
This example keeps asking the user for a number until the number is the correct one.
How to build
bash
kotlinc src/**/*.kt -d buildHow to run
bash
kotlin -cp build project005.GuessKtNoteworthy
- In this example we use another java class for the sake of the example: Scanner
- We had to
importthat class, since that one isn't from the java.lang package. - Scanner deals with closeable resources, so we can use the use kotlin extension function.
- When we created the Scanner, we passed System.
inas parameter. The backticks are escaping theinbecause it's a reserved word in kotlin but not in java. Kotlin also permits special identifiers using backticks in tests.
See docs for further details.