-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.go
63 lines (51 loc) · 935 Bytes
/
array.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import "fmt"
func main() {
fmt.Println("Array")
var names [4]string
names[0] = "somad"
names[1] = "aldo"
names[2] = "sule"
names[3] = "darman"
fmt.Println(names)
// inisialisasi
fmt.Println("\nInisialisasi")
var fruits = [4]string{
"apple", "orange", "watermelon", "peer",
}
fmt.Println(fruits)
// inisial tanpa nilai awal array
fmt.Println("\nInisial tanpa nilai awal")
var numbers = [...]int{1, 2, 3, 4, 5, 6, 7}
fmt.Println(numbers)
// array multidimensi
fmt.Println("\nMultidimensi array")
var numbers1 = [3][2]int{
[2]int{
3, 2,
},
[2]int{
2, 3,
},
[2]int{
6, 5,
},
}
var numbers2 = [3][2]int{
{
3, 2,
}, {
2, 3,
}, {
6, 5,
},
}
fmt.Println(numbers1)
fmt.Println(numbers2)
// For Array
fmt.Println("\nFor array")
var fruits2 = [1]string{0: "test"}
for i := 0; i < len(fruits2); i++ {
fmt.Printf("elemen %d : %s\n", i, fruits2[i])
}
}