/* *2. init 函数会检查长和宽是否大于0 */ func init() { println("main package initialized") if rectLen < 0 { log.Fatal("length is less than zero") //fmt.Println("length is less than zero") } if rectWidth < 0 { log.Fatal("width is less than zero") //fmt.Println("width is less than zero") } } func main() { //fmt.Println("Geometrical shape properties") //var rectLen, rectWidth float64 = 6, 7 fmt.Println("Geometrical shape properties") /*Area function of rectangle package used*/ fmt.Printf("area of rectangle %.2f\n", rectangle.Area(rectLen, rectWidth)) /*Diagonal function of rectangle package used*/ fmt.Printf("diagonal of the rectangle %.2f ", rectangle.Diagonal(rectLen, rectWidth)) } 【 在 StephenLee 的大作中提到: 】 : 能放完整程序么,看起来 import 包并没有被调用 : - 来自「最水木 for iPhone13,2」 -- FROM 120.242.252.*
关键是输出顺序不固定,我偶尔也有你这样的输出 main package initialized rectangle package initialized Geometrical shape properties area of rectangle 42.00 diagonal of the rectangle 9.22