관심있는 것들 정리
Golang 연습 3 (99 bottles of beer) 본문
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)
}
}
}
반응형
'programming > Golang' 카테고리의 다른 글
Golang 연습 6 (channel close check) (0) | 2021.01.26 |
---|---|
Golang 연습 5 (duck typing using interface) (0) | 2021.01.26 |
Golang 연습 4 (slice traversal) (0) | 2021.01.25 |
Golang 연습 2 (goroutine w/ loop) (0) | 2021.01.25 |
golang 연습 1 (waitgroup) (0) | 2021.01.25 |