관심있는 것들 정리

Golang 연습 3 (99 bottles of beer) 본문

programming/Golang

Golang 연습 3 (99 bottles of beer)

내공강화 2021. 1. 25. 11:31
package main

import (
	"fmt"
)

func main() {
	for i := 99; i > 0; i-- {
		var unit string
		switch {
		case i > 1:
			unit = "bottles"
		case 1 == i:
			unit = "bottle"
		}
		fmt.Printf("%v %s of beer on the wall, %v %s of beer.\n", i, unit, i, unit)
		if 1 == (i - 1) {
			unit = "bottle"
			fmt.Printf("Take one down, pass it around, %v %s of beer on the wall.\n", i-1, unit)
		} else if 0 == (i - 1) {
			fmt.Printf("Take one down, pass it around, No more bottles of beer on the wall.\n")
			fmt.Printf("No more bottles of beer on the wall, No more bottles of beer.\n")
			fmt.Printf("Go to the store and buy some more, 99 bottles of beer on the wall.\n")
		} else {
			fmt.Printf("Take one down, pass it around, %v %s of beer on the wall.\n", i-1, unit)
		}
	}
}
반응형