提交 217f6eda 编写于 作者: D Dmitry Jemerov

bottles are a bit nicer now

上级 20520e99
...@@ -3,21 +3,25 @@ namespace bottles; ...@@ -3,21 +3,25 @@ namespace bottles;
fun main(args: Array<String>) { fun main(args: Array<String>) {
var bottles: Int = 99; var bottles: Int = 99;
while(bottles > 0) { while(bottles > 0) {
System.out?.print(bottles) System.out?.print(bottlesOfBeer(bottles))
System.out?.print(if (bottles > 1) " bottles" else " bottle") System.out?.print(" on the wall, ")
System.out?.print(" of beer on the wall, ") System.out?.print(bottlesOfBeer(bottles))
System.out?.print(bottles) System.out?.println(".")
System.out?.print(if (bottles > 1) " bottles" else " bottle")
System.out?.println(" of beer.")
System.out?.print("Take one down, pass it around, ") System.out?.print("Take one down, pass it around, ")
bottles -= 1; bottles -= 1;
if (bottles == 0) { if (bottles == 0) {
System.out?.print("no more bottles of beer on the wall.") System.out?.print("no more bottles of beer on the wall.")
} }
else { else {
System.out?.print(bottles) System.out?.print(bottlesOfBeer(bottles))
System.out?.print(if (bottles > 1) " bottles" else " bottle") System.out?.println(" on the wall.")
System.out?.println(" of beer on the wall.")
} }
} }
} }
fun bottlesOfBeer(count: Int): String? {
val result = new StringBuilder()
result.append(count)
result.append(if (count > 1) " bottles of beer" else " bottle of beer")
return result.toString()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册