Skip to content

Instantly share code, notes, and snippets.

@726f737479
Last active May 23, 2024 13:36
Show Gist options
  • Save 726f737479/4220a55a16de0171b279e362c6227e83 to your computer and use it in GitHub Desktop.
Save 726f737479/4220a55a16de0171b279e362c6227e83 to your computer and use it in GitHub Desktop.
Kotlin
fun drawRating(vote: Int): String {
if (vote >= 0 && vote <= 20) {
return "★☆☆☆☆"
}
else if (vote > 20 && vote <= 40) {
return "★★☆☆☆"
}
else if (vote > 40 && vote <= 60) {
return "★★★☆☆"
}
else if (vote > 60 && vote <= 80) {
return "★★★★☆"
}
else if (vote > 80 && vote <= 100) {
return "★★★★★"
}
else {
return "☆☆☆☆☆"
}
}
println(drawRating(0) ); // ★☆☆☆☆
println(drawRating(1) ); // ★☆☆☆☆
println(drawRating(50)); // ★★★☆☆
println(drawRating(99)); // ★★★★★
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment