Created
May 29, 2018 03:37
-
-
Save ivalexandru/b9c7026fc933d8595f08cb721e06f602 to your computer and use it in GitHub Desktop.
Kotlin_Functions_lvl2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.math.pow | |
import java.util.* | |
fun main(args: Array<String>) { | |
//extra-practice: | |
//Use a for loop to run the program 10 times, or until the "Take it easy" fortune has been selected. | |
var fortune: String | |
for (i in 1..10) { | |
fortune = getFortune() | |
println("\nYour fortune is: $fortune") | |
if (fortune.contains("Take it easy")) break | |
} | |
} | |
fun getFortune() : String { | |
val fortunes = listOf( "You will have a great day!", | |
"Things will go well for you today.", | |
"Enjoy a wonderful day of success.", | |
"Be humble and all will turn out well.", | |
"Today is a good day for exercising restraint.", | |
"Take it easy and enjoy life!", | |
"Treasure your friends, because they are your greatest fortune.") | |
print("\nEnter your birthday: ") | |
val birthday: Int = readLine()?.toIntOrNull() ?: 1 | |
return fortunes[birthday.rem(fortunes.size)] | |
// rem Calculates the REMainder of dividing this value by the other value. * | |
// println(4.rem(3)) // 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment