Skip to content

Instantly share code, notes, and snippets.

@nbness2
Created November 27, 2021 11:29
Show Gist options
  • Save nbness2/826bf6bd3e0d5fc993f71a4110841929 to your computer and use it in GitHub Desktop.
Save nbness2/826bf6bd3e0d5fc993f71a4110841929 to your computer and use it in GitHub Desktop.
val random = Random
val positiveInts = 1 .. Int.MAX_VALUE
val negativeInts = -1 downTo Int.MIN_VALUE
val sign = when(val randomNumber = random.nextInt()) {
in positiveInts -> "positive $randomNumber"
in negativeInts -> "negative $randomNumber"
else -> "zero"
}
println("Number is $sign")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment