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
| package main
import "fmt"
type temperature struct { high, low celsius } type location struct { lat, long float64 } type report struct { sol int temperature location } type celsius float64
func (t temperature) average() celsius { return (t.high + t.low) / 2 }
func main() {
boadbury := location{-14.5684, 175.472636} tem1 := temperature{high: -1.0, low: -78.0} report1 := report{15, tem1, boadbury}
fmt.Println("平均温度为", report1.average()) fmt.Println("最高温度为", report1.high)
}
|