2019年6月5日水曜日

開発環境

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 medal, rank := range ranks {
  fmt.Printf("The %s medal's rank is %d\n", medal, rank)
 }
}

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

$ go run sample3.go 
The silver medal's rank is 2
The bronze medal's rank is 3
The gold medal's rank is 1
$ 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
$ go run sample3.go 
The gold medal's rank is 1
The silver medal's rank is 2
The bronze medal's rank is 3
$ go run sample3.go 
The gold medal's rank is 1
The silver medal's rank is 2
The bronze medal's rank is 3
$ go run sample3.go 
The gold medal's rank is 1
The silver medal's rank is 2
The bronze medal's rank is 3
$ 

0 コメント:

コメントを投稿