Hey All, I’m working through the jetbrains academy material for Kotlin, and I’m obviously doing this the worng way. Can someone help me out. Problem below
Write a program that reads an integer number and checks if it is divisible by 2, 3, 5, and 6.
If the number is divisible by M, the program should output “Divided by M”.
The program should check all the divisors listed above. The order of divisors in the result can be any.
My answer
val num = readln().toInt()
I input 12
if(num % 2 == 0){
println(“Divided by 2”)
} else if(num % 3 == 0 ){
println(“Divided by 3”)
} else if(num % 5 == 0){
println(“Divided by 5”)
}else if (num % 6 == 0){
println(“Divided by 6”)
}
I receive “Divided by 2”, but also I want to receive “Divided by 3” and “Divided by 6” additionally. Like the following :
Divided by 2
Divided by 3
Divided by 6
How can I get this?
submitted by /u/Ilovesoup86
[link] [comments]