42 lines
767 B
Go
42 lines
767 B
Go
package main
|
||
|
||
import "fmt"
|
||
|
||
func main() {
|
||
// 1. 基础 Hello World
|
||
fmt.Println("Hello, World!")
|
||
|
||
// 2. 多行输出
|
||
fmt.Println("这是第一行")
|
||
fmt.Println("这是第二行")
|
||
fmt.Println("这是第三行")
|
||
|
||
// 3. 格式化输出
|
||
name := "思语"
|
||
age := 25
|
||
fmt.Printf("你好,我是 %s,今年 %d 岁!\n", name, age)
|
||
|
||
// 4. 简单计算
|
||
a := 10
|
||
b := 20
|
||
fmt.Printf("%d + %d = %d\n", a, b, a+b)
|
||
fmt.Printf("%d * %d = %d\n", a, b, a*b)
|
||
|
||
// 5. 条件判断示例
|
||
score := 85
|
||
if score >= 90 {
|
||
fmt.Println("优秀!")
|
||
} else if score >= 80 {
|
||
fmt.Println("良好!")
|
||
} else {
|
||
fmt.Println("继续努力!")
|
||
}
|
||
|
||
// 6. 循环示例
|
||
fmt.Println("Counting from 1 to 5:")
|
||
for i := 1; i <= 5; i++ {
|
||
fmt.Printf("%d ", i)
|
||
}
|
||
fmt.Println()
|
||
}
|