K
K
Koteuky2021-12-05 19:16:41
Kotlin
Koteuky, 2021-12-05 19:16:41

How to implement random text output in kotlin?

I want to make a module that will display random breeds, but I don't understand how to implement it. Please tell me how to implement this

fun main {

val i1 = "Cat breeds: British, etc"
val i2 = "Dog breeds: bulldogs, etc"
val i3 = "Horse breeds: mustang, etc"

val rand = (i1..i3).random()

print(rand)

}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Siomin, 2021-12-05
@Koteuky

fun main() {
   

    val i1 = "Породы кошек:британнцы и т.д"
    val i2 = "Породы собак:бульдоги и т.д"
    val i3 = "Породы лошадей:мустанг и т.д"

    val random = arrayOf(i1,i2,i3)
    val rand = random.nextInt(0, 2 + 1)

    print(random[rand])
}

P
Pavel Shvedov, 2021-12-05
@mmmaaak

Put the text into an array and generate a random index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question