func main() { i := 5 fmt.Println("Is %d even? %v", i, even.Even(i)) // dead, because odd is a private function of even //fmt.Println("Is %d even? %v", i, even.odd(i)) }
func main() { f.Println(` 包是函数和数据的集合。用package保留字定义一个包。文件名不需要与包名一致。 包名的约定是使用小写字符。 Go包可以由多个文件组成, 但是使用相同的package<name>这一行。 `) f.Println(even.Even(10)) }
func main() { i := 5 fmt.Printf("Is %d even? %v\n", i, even.Even(i)) helloworld.Helloworld() typeExample.TypeExample() interfaceExample.InterfaceExample() listExample.ListExample() funcExample.TestA() a := []byte{'1', '2', '3', '4'} var x int for i := 2; i < len(a); { x, i = funcExample.NextInt(a, i) println(x) println(i) } println("------------------------") funcExample.DeferTest1() i = funcExample.DeferTest2() fmt.Printf("%v\n", i) funcExample.MultiArgsTest(1, 2, 3, 4, 5) funca := func() { println("hello world") } funca() funcb := func(s string) { println(s) } funcExample.PassFuncTest("hello function", funcb) funcExample.FuncMap() funcc := func(i int) { println(1 / i) } funcExample.ThrowsPanic(funcc) var sb structExample.S pa := &sb //a := new(structExample.S) structExample.F1(pa) structExample.F2(pa) println(sb.Get()) println(pa.Get()) goroutineExample.Gogo() ioExample.IoExample() ioExample.ExecExample() }
func main() { fmt.Println("Please enter your full name: ") fmt.Scanln(&firstName, &lastName) // fmt.Scanf("%s %s", &firstName, &lastName) fmt.Printf("Hi %s %s!\n", firstName, lastName) // Hi Chris Naegels fmt.Sscanf(input, format, &f, &i, &s) fmt.Println("From the string we read: ", f, i, s) k := 7 fmt.Println("k is even ", even.Even(k)) arr.TestArr() arr.TestSlice() x.ReadX() fmt.Println("x.ReadBuf...................") x.ReadBuf("g://jobs.txt") // ouwtput: From the string we read: 56.12 5212 Go }
func main() { i := 5 fmt.Printf("Is %d even? %v\n", i, even.Even(i)) |\longremark{Use the function from the % \package{even} package. The syntax for accessing a function from a package is % \lstinline{<package>.Function()}.}|
func main() { i := 5 fmt.Printf("Is %d even? %v\n", i, even.Even(i)) |\longremark{调用 \package{even} 包中的函数。% 访问一个包中的函数的语法是 \lstinline{<package>.Function()}。}|
func main() { for i := 0; i <= 100; i++ { fmt.Printf("Is the interger %d even? %v\n", i, even.Even(i)) } }
func main() { i := 5 fmt.Printf("Is %d even? %v\n", i, even.Even(i)) //<4> }
func evenTest() { i := 5 fmt.Printf("Is %d even? %v\n", i, even.Even(i)) }