Skip to content

Instantly share code, notes, and snippets.

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