Files
test/chapters/chapter-1/hello.go

42 lines
767 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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()
}