|
| 1 | +// 1 -) 5 string elemandan oluşan bir array ve 5 int elemandan oluşan slice oluşturup index numaralarıyla birlikte gösterelim. |
| 2 | + |
| 3 | +/* package main |
| 4 | +
|
| 5 | +import "fmt" |
| 6 | +
|
| 7 | +func main() { |
| 8 | +
|
| 9 | + myArr := [5]string{"tahran", "belgrad", "roma", "tiflis", "moskova"} |
| 10 | +
|
| 11 | + for index, value := range myArr { |
| 12 | + fmt.Println(index, value) |
| 13 | + } |
| 14 | +
|
| 15 | + fmt.Println() |
| 16 | +
|
| 17 | + mySlc := []int{1, 2, 3, 4, 5} |
| 18 | +
|
| 19 | + for i, v := range mySlc { |
| 20 | + fmt.Println(i, v) |
| 21 | + } |
| 22 | +
|
| 23 | +} */ |
| 24 | + |
| 25 | +// 2 -) [0,1,2,3,4,5,6,7,8] slice dan [0,1,2,3], [4,5,6], [6,7,8], [2,3,6,7] slicelarını oluşturunuz. |
| 26 | + |
| 27 | +/* package main |
| 28 | +
|
| 29 | +import "fmt" |
| 30 | +
|
| 31 | +func main() { |
| 32 | +
|
| 33 | + mySlc := []int{0, 1, 2, 3, 4, 5, 6, 7, 8} |
| 34 | +
|
| 35 | + mySlc1 := mySlc[:4] |
| 36 | + fmt.Println(mySlc1) |
| 37 | + mySlc2 := mySlc[4:7] |
| 38 | + fmt.Println(mySlc2) |
| 39 | + mySlc3 := mySlc[6:] |
| 40 | + fmt.Println(mySlc3) |
| 41 | +
|
| 42 | + mySlc4 := append(mySlc[2:4], mySlc[6:8]...) |
| 43 | + fmt.Println(mySlc4) |
| 44 | +
|
| 45 | +} */ |
| 46 | + |
| 47 | +// 3 -) slicelar için copy metodunu ve assign ( = ) ile farkını açıklayınız. |
| 48 | +/* |
| 49 | +package main |
| 50 | +
|
| 51 | +import "fmt" |
| 52 | +
|
| 53 | +func main() { |
| 54 | +
|
| 55 | + mySlc := []int{1, 2, 3} |
| 56 | + mySlc2 := make([]int, 2) |
| 57 | +
|
| 58 | + fmt.Println(mySlc) |
| 59 | + fmt.Println(mySlc2) |
| 60 | +
|
| 61 | + copy(mySlc2, mySlc) |
| 62 | + fmt.Println(mySlc) |
| 63 | + fmt.Println(mySlc2) |
| 64 | +
|
| 65 | + mySlc[0] = 100 |
| 66 | + fmt.Println(mySlc) |
| 67 | + fmt.Println(mySlc2) */ |
| 68 | + |
| 69 | +/* mySlc := []int{1, 2, 3} |
| 70 | + mySlc2 := make([]int, 2) |
| 71 | +
|
| 72 | + fmt.Println(mySlc) |
| 73 | + fmt.Println(mySlc2) |
| 74 | +
|
| 75 | + mySlc2 = mySlc |
| 76 | + fmt.Println(mySlc) |
| 77 | + fmt.Println(mySlc2) |
| 78 | +
|
| 79 | + mySlc[0] = 100 |
| 80 | + fmt.Println(mySlc) |
| 81 | + fmt.Println(mySlc2) |
| 82 | +
|
| 83 | +}*/ |
| 84 | + |
| 85 | +// 4 -) map gösterimi ile yazar ve yazarlara ait kitapların isimlerini for range ile gösterin. |
| 86 | + |
| 87 | +package main |
| 88 | + |
| 89 | +import "fmt" |
| 90 | + |
| 91 | +func main() { |
| 92 | + |
| 93 | + myMap := map[string][]string{ |
| 94 | + "Yaşar Kemal": []string{"İnce Memed", "Yer Demir Gök Bakır"}, |
| 95 | + "Sabahattin Ali": []string{"Kuyucaklı Yusuf", "Kürk Mantolu Madonna", "Değirmen"}, |
| 96 | + "Haruki Murakami": []string{"1Q84", "Dans Dans Dans", "Kumandanı Öldürmek"}, |
| 97 | + } |
| 98 | + |
| 99 | + /* fmt.Println(myMap) |
| 100 | + fmt.Println(myMap["Sabahattin Ali"]) |
| 101 | + fmt.Println(myMap["Haruki Murakami"][0]) */ |
| 102 | + |
| 103 | + for key, value := range myMap { |
| 104 | + fmt.Println("Yazarımız: ", key) |
| 105 | + fmt.Println("Bazı kitapları aşağıdadır:") |
| 106 | + for i, v := range value { |
| 107 | + fmt.Println("\t", i+1, v) |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | +} |
0 commit comments