2019年7月27日土曜日

開発環境

Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 7(labeling data - Maps)、Code Magnets(226)の解答を求めてみる。

コード

package main

import "fmt"

func main() {
 ranks := map[string]int{"gold": 1, "silver": 2, "bronze": 3}
 for i := 0; i < 5; i++ {
  for medal, rank := range ranks {
   fmt.Printf("The %s medal's rank is %d\n", medal, rank)
  }
  fmt.Println()
 }
}

入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)

$ go run sample3.go
The bronze medal's rank is 3
The gold medal's rank is 1
The silver medal's rank is 2

The gold medal's rank is 1
The silver medal's rank is 2
The bronze medal's rank is 3

The bronze medal's rank is 3
The gold medal's rank is 1
The silver medal's rank is 2

The silver medal's rank is 2
The bronze medal's rank is 3
The gold medal's rank is 1

The gold medal's rank is 1
The silver medal's rank is 2
The bronze medal's rank is 3

$ 

0 コメント:

コメントを投稿