From 217f6eda3258c178039f7f7162a8760ddc22b971 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 14 Apr 2011 20:08:28 +0200 Subject: [PATCH] bottles are a bit nicer now --- examples/src/Bottles.jetl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/src/Bottles.jetl b/examples/src/Bottles.jetl index 43d2d0c3b26..8ae5408d13b 100644 --- a/examples/src/Bottles.jetl +++ b/examples/src/Bottles.jetl @@ -3,21 +3,25 @@ namespace bottles; fun main(args: Array) { var bottles: Int = 99; while(bottles > 0) { - System.out?.print(bottles) - System.out?.print(if (bottles > 1) " bottles" else " bottle") - System.out?.print(" of beer on the wall, ") - System.out?.print(bottles) - System.out?.print(if (bottles > 1) " bottles" else " bottle") - System.out?.println(" of beer.") + System.out?.print(bottlesOfBeer(bottles)) + System.out?.print(" on the wall, ") + System.out?.print(bottlesOfBeer(bottles)) + System.out?.println(".") System.out?.print("Take one down, pass it around, ") bottles -= 1; if (bottles == 0) { System.out?.print("no more bottles of beer on the wall.") } else { - System.out?.print(bottles) - System.out?.print(if (bottles > 1) " bottles" else " bottle") - System.out?.println(" of beer on the wall.") + System.out?.print(bottlesOfBeer(bottles)) + System.out?.println(" 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() +} -- GitLab