2018年8月10日金曜日

開発環境

  • macOS High Sierra - Apple (OS)
  • Emacs (Text Editor)
  • Go (プログラミング言語)

Introducing Go: Build Reliable, Scalable Programs (Caleb Doxsey (著)、O'Reilly Media)のChapter 5.(Arrays, Slices, and Maps)、Exercises(No. 854)1.を取り組んでみる。

コード(Emacs)

package main

import "fmt"

func main() {
 fmt.Println("array")
 x := [5]string{"a", "b", "c", "d", "e"}
 fmt.Println(x, x[3])

 y := [5]int{
  10,
  20,
  30,
  40,
  50,
 }
 fmt.Println(y, y[3])

 fmt.Println("slice")
 z := []string{"A", "B", "C", "D", "E"}
 fmt.Println(z, z[3])

 w := []int{
  10,
  20,
  30,
  40,
  50,
 }
 fmt.Println(w, w[3])
 v := []float64{1.2, 2.3}
 v = append(v, 3.4, 4.5, 5.6)
 fmt.Println(v, v[3])
}

入出力結果(Terminal)

$ go run sample1.go
array
[a b c d e] d
[10 20 30 40 50] 40
slice
[A B C D E] D
[10 20 30 40 50] 40
[1.2 2.3 3.4 4.5 5.6] 4.5
$

0 コメント:

コメントを投稿