-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.go
198 lines (161 loc) · 3.25 KB
/
hello.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package main
import (
"fmt"
"math"
"rsc.io/quote/v4"
)
func describeTheStringSlice(s []string) {
fmt.Println("length:", len(s))
for i := 0; i < len(s); i++ {
fmt.Println("*", s[i])
}
}
func koleczko() {
i := 2
for i < 20 {
fmt.Println(math.Pow(float64(i), 2.0))
i++
}
}
func divisibleByThirteen() {
for i := 0; i < 100; i++ {
if i%13 == 0 {
fmt.Println("Dvisible by 13: ", i)
} else if i%17 == 0 {
fmt.Println("Dvisible by 17: ", i)
} else {
fmt.Println(i, "not divisible by 13 nor 17 :(")
}
}
}
func matma() {
const a = 20e5
const b = 0.713
const c = a / b
fmt.Println("c:", c, "sinus:", math.Sin(b))
}
func summy() {
var a, b int = 13, 45
fmt.Println(a + b)
a = 19
fmt.Println(a + b)
}
func doit() {
var a = "Adrian"
b := "Gonciarz"
fmt.Println(a, b)
}
func tempSwitch(temp int) {
switch {
case temp < 0:
fmt.Println("zimno kurrrrr....")
case temp < 25:
fmt.Println("elegancko")
case temp >= 25:
fmt.Println("caliente")
}
}
func simpleSwitch(value float32) {
switch value {
case 0.0:
fmt.Println("pustka")
case 1.0, 3.0:
fmt.Println("dobro")
default:
fmt.Println("no tak nie wiadomo do końca")
}
}
func arrayFun() {
var a [5]int
fmt.Println("empty:", a)
a[0] = 5
fmt.Println("curent:", a)
fmt.Println("Len of array:", len(a))
b := [5]int{0, 11, 33, 49, 39}
fmt.Println(b)
var twoDimArray [3][3]int
for i := 1; i <= 3; i++ {
for j := 1; j <= 3; j++ {
twoDimArray[i-1][j-1] = i * j
}
}
fmt.Println(twoDimArray)
}
func slicesFun() {
students := make([]string, 5)
students[0] = "[email protected]"
students[1] = "[email protected]"
students[2] = "[email protected]"
fmt.Println(students)
fmt.Println(len(students))
students = append(students, "[email protected]")
describeTheStringSlice(students)
fmt.Println("First two students", students[:2])
fmt.Println("Middle students", students[3:6])
}
func arrayReferences() {
var ar1 [4]int
ar2 := ar1
ar1[0] = 42
ar2[0] = 24
fmt.Println(ar1, ar2)
dynArr := [...]string{"cos", "coss", "asd", "Asd2134"}
fmt.Println(len(dynArr))
}
func slicing() {
ar1 := [4]string{"f", "oo", "ba", "r"}
sl1 := ar1[1:3]
sl1 = append(sl1, "du", "pa")
fmt.Println(sl1)
var emptySlice []string
fmt.Println(len(emptySlice))
emptySlice = append(emptySlice, "d", "r", "b")
fmt.Println(emptySlice)
}
func mapFun() {
scores := make(map[string]int)
scores["adi"] = 12
scores["pat"] = 8
scores["sam"] = 32
scores["mar"] = 52
delete(scores, "sam")
fmt.Println(scores)
users := map[string]bool{"a": true, "b": false, "c": true}
fmt.Println(users)
}
func rangeTest() {
scores := []float32{3.4, 3.3, 7.8, 9.0, 1.9, 4.2}
for idx, score := range scores {
fmt.Printf("Score %f at index %d\n", score, idx)
}
users := map[string]bool{"a": true, "b": false, "c": true}
for k, v := range users {
fmt.Printf("\tMap key %s is %t\n", k, v)
}
}
func main() {
fmt.Println(quote.Go())
fmt.Println("Foo" + "Bar")
fmt.Println(1 + 2)
fmt.Println(true && false)
fmt.Println(7.0 / 3)
doit()
summy()
matma()
koleczko()
divisibleByThirteen()
tempSwitch(-5)
tempSwitch(0)
tempSwitch(15)
tempSwitch(25)
tempSwitch(26)
simpleSwitch(1.0)
simpleSwitch(2.0)
simpleSwitch(3.0)
arrayFun()
slicesFun()
arrayReferences()
slicing()
mapFun()
rangeTest()
}