go routine和字符,实际是数字

点击查看代码
package main

import (
	"fmt"
	"time"
)

func numbers() {
	for i := 1; i <= 5; i++ {
		time.Sleep(250 * time.Millisecond)
		fmt.Printf("%d ", i)
	}
}
func alphabets() {
	for i := 'a'; i <= 'e'; i++ { // 此处的i是`a`对应的ascii码的数字位置
		time.Sleep(400 * time.Millisecond)
		fmt.Printf(" (%c>>%d--%v) " , i,i,i)
	}
}
func main() {
	go numbers()
	go alphabets()
	time.Sleep(3000 * time.Millisecond)
	fmt.Println("main terminated")
}

posted @ 2022-03-10 21:01  ty1539  阅读(19)  评论(0编辑  收藏  举报