计算一个数的平方的方法
package main import ( "fmt" ) func main() { var b float64 var a float64 = 42 b = a * a fmt.Println("结果", b) }
package main import ( "fmt" "math" ) func main() { var b float64 var a float64 = 42 b = math.Pow(a, 2) fmt.Println("结果", b) }
package main import "fmt" func main() { var name string var age int fmt.Print("请输入您的姓名") fmt.Scanln(&name) fmt.Println("请输入您的年龄") fmt.Scanln(&age) fmt.Println("姓名%s,年龄%d\n", name, age) }
package main import "fmt" func main() { a, b := 7, 9 if a > b { fmt.Println("大于") } else { fmt.Println("小于") } }
package main import "fmt" func main() { for i := 0; i < 100; i++ { fmt.Println(i) } }
package main import "fmt" func main() { i := 1 for i < 10 { i++ fmt.Println(i) } }
package main import "fmt" func main() { for i := 0; i < 9; i++ { for j := 0; j < 9; j++ { if i == 5 { fmt.Printf("%d x %d =%d\t", i, j, i*j) continue } else if i > 5 { break } } } }