package main
import "fmt"
func main() {
var number int = 5
if number += 4; 10 > number {
number := 0
number += 3
fmt.Print(number)
} else if 10 < number {
number -= 2
fmt.Print(number)
}
fmt.Println(number)
}
import "fmt"
func main() {
var number int = 5
if number += 4; 10 > number {
number := 0
number += 3
fmt.Print(number)
} else if 10 < number {
number -= 2
fmt.Print(number)
}
fmt.Println(number)
}
2018-09-05
func read(file *os.File)([]byte, error) {
br := bufio.NewReader(file)
var buf bytes.Bufferfor {ba, isPrefix, err := br.ReadLine()
if err != nil { if err == io.EOF { break } return nil, err } buf.Write(ba) if !isPrefix { buf.WriteByte('\n') } }
return buf.Bytes(), nil
}
br := bufio.NewReader(file)
var buf bytes.Bufferfor {ba, isPrefix, err := br.ReadLine()
if err != nil { if err == io.EOF { break } return nil, err } buf.Write(ba) if !isPrefix { buf.WriteByte('\n') } }
return buf.Bytes(), nil
}
2018-07-31
最简单没有之一
func main() {
for i := 0; i < 10; i++ {
fmt.Printf("%d ", fibonacci(i))
defer fmt.Printf("%d ", fibonacci(i))
}
}
func fibonacci(num int) int {
if num == 0 {
return 0
}
if num < 2 {
return 1
}
return fibonacci(num-1) + fibonacci(num-2)
}
func main() {
for i := 0; i < 10; i++ {
fmt.Printf("%d ", fibonacci(i))
defer fmt.Printf("%d ", fibonacci(i))
}
}
func fibonacci(num int) int {
if num == 0 {
return 0
}
if num < 2 {
return 1
}
return fibonacci(num-1) + fibonacci(num-2)
}
2018-07-11
package main
import "fmt"
func main() {
var number int = 5
if number += 4; 10 > number {
number += 27
number += 3
fmt.Print(number)
} else if 10 < number {
number -= 2
fmt.Print(number)
}
fmt.Println(number)
}
import "fmt"
func main() {
var number int = 5
if number += 4; 10 > number {
number += 27
number += 3
fmt.Print(number)
} else if 10 < number {
number -= 2
fmt.Print(number)
}
fmt.Println(number)
}
2018-07-10
package main
import "fmt"
type Animal interface {
}
type Cat struct {
name string
age int
addr string
}
func main() {
myCat := Cat{"Little C", 2, "In the house"}
animal, ok := interface{}(&myCat).(Animal)
fmt.Print(animal)
fmt.Printf("%v, %v\n", ok, animal)
}
import "fmt"
type Animal interface {
}
type Cat struct {
name string
age int
addr string
}
func main() {
myCat := Cat{"Little C", 2, "In the house"}
animal, ok := interface{}(&myCat).(Animal)
fmt.Print(animal)
fmt.Printf("%v, %v\n", ok, animal)
}
2018-07-05
func main() {
ch1 := make(chan int)
ch2 := make(chan int)
ch3 := make(chan int)
go func() {
fmt.Println("1")
ch1 <- 1
}()
go func() {
<- ch1
fmt.Println("2")
ch2 <- 1
}()
go func() {
<- ch2
fmt.Println("3")
ch3 <- 1
}()
<- ch3
}
ch1 := make(chan int)
ch2 := make(chan int)
ch3 := make(chan int)
go func() {
fmt.Println("1")
ch1 <- 1
}()
go func() {
<- ch1
fmt.Println("2")
ch2 <- 1
}()
go func() {
<- ch2
fmt.Println("3")
ch3 <- 1
}()
<- ch3
}
2018-06-05