-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (87 loc) · 1.26 KB
/
main.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
package main
import (
"fmt"
"math"
)
type Circle struct {
x, y, r float64
}
func main() {
{
var str = "Hello Go"
fmt.Println(str)
i := 1
for i <= 10 {
fmt.Println(i)
i = i + 1
}
if i%2 == 0 {
// even
} else {
// odd
}
for i := 1; i <= 10; i++ {
// iterate 10 times
}
switch i {
case 10:
fmt.Println("i is 10")
default:
fmt.Println("i is not 10")
}
}
var y [5]int
y[4] = 100
fmt.Println(y)
{
z := make([]float64, 10)
z2 := append(z, 1)
fmt.Println(z2)
}
/* {
var a map[string]int
a["key"] = 10
fmt.Println(a)
b := make(map[int]int)
b[1] = 10
delete(b, 1)
}*/
{
xfl := []float64{98, 93, 77, 82, 83}
fmt.Println(average(xfl))
fmt.Println(add(1, 2, 3))
sub := func(a int, b int) int {
return a - b
}
fmt.Println(sub(1, 2))
}
defer func() {
defer func() {
str := recover()
fmt.Println(str)
}()
panic("PANIC")
}()
{
c := new(Circle)
c.r = 5
fmt.Println(c.area())
}
}
func (c *Circle) area() float64 {
return math.Pi * math.Pow(c.r, 2)
}
func average(xs []float64) float64 {
total := 0.0
for _, v := range xs {
total += v
}
return total / float64(len(xs))
}
func add(args ...int) int {
total := 0
for _, v := range args {
total += v
}
return total
}