1. 程式人生 > >Go語言中的map用法

Go語言中的map用法

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var m map[int]map[int]string
	m = make(map[int]map[int]string)
	for i := 0; i < 10; i++ {
		m[i] = make(map[int]string)
		for j := 0; j < 3; j++ {
			m[i][j] = "(" + strconv.Itoa(i) + "+" + strconv.Itoa(j) + ")"
		}
	}

	//列印結果
	for i := 0; i < 10; i++ {
		for j := 0; j < 3; j++ {
			fmt.Print(m[i][j])
			fmt.Print(" ")
		}
		fmt.Println("\n")
	}

}