mirror of
https://github.com/RustyRaptor/golang_study.git
synced 2026-12-03 15:45:24 -07:00
renamed to main.go and wrote some beginner code.
This commit is contained in:
1 parent
2211a6d3de
commit
8164b83b0a
1 file changed
+49
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func add(x, y int) int {
|
||||
return x + y
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, World!")
|
||||
|
||||
fmt.Println("The time is", time.Now())
|
||||
|
||||
fmt.Println("My favorite number is", rand.Intn(10))
|
||||
|
||||
fmt.Printf("Now you have %v problems.\n", math.Sqrt(7))
|
||||
|
||||
fmt.Println(math.Pi)
|
||||
|
||||
fmt.Println(add(42, 13))
|
||||
|
||||
var i, j int = 1, 2
|
||||
|
||||
fmt.Println(i, j)
|
||||
|
||||
var c, python, java = true, false, "no!" // type inference
|
||||
// without type inference
|
||||
// var c bool = true
|
||||
// var python bool = false
|
||||
// var java string = "no!"
|
||||
|
||||
fmt.Println(c, python, java)
|
||||
|
||||
const Pi float32 = 3.14
|
||||
fmt.Println(Pi)
|
||||
|
||||
var sum int = 0
|
||||
for i := 0; i < 10; i++ {
|
||||
sum += i
|
||||
}
|
||||
|
||||
fmt.Println(sum)
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user