본문 바로가기
IT

[Swift & Go] 99병의 맥주

by %? 2022. 6. 21.

Swift

import Foundation

print("99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall.")

for i in (2...98).reversed()
{
	if(i==2)
	{
		print("2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall.")
	}
	else
	{
		print(i, "bottles of beer on the wall,", i, "bottles of beer. Take one down and pass it around,", i-1, "bottles of beer on the wall.")
	}
}

print("1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around, no more bottles of beer on the wall.\nNo more bottles of beer on the wall, no more bottles of beer.Go to the store and buy some more, 99 bottles of beer on the wall.")

 

Go

 

package main

import "fmt"

func main() {
	i := 0
	fmt.Print("99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall.\n")
	for i = 98; i >= 2; i-- {
		if i == 2 {
			fmt.Print("2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall.\n")
		} else {
			fmt.Print(i, " bottles of beer on the wall, ", i, " bottles of beer. Take one down and pass it around, ", i-1, " bottles of beer on the wall.\n")
		}
}
	fmt.Print("1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around, no more bottles of beer on the wall.\nNo more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.")
}