mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 22:53:43 +08:00
25 lines
597 B
Go
25 lines
597 B
Go
// read input from the console:
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
firstName, lastName, s string
|
|
i int
|
|
f float32
|
|
input = "56.12 / 5212 / Go"
|
|
format = "%f / %d / %s"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("Please enter your full name: ")
|
|
fmt.Scanln(&firstName, &lastName)
|
|
// fmt.Scanf("%s %s", &firstName, &lastName)
|
|
fmt.Printf("Hi %s %s!\n", firstName, lastName) // Hi Chris Naegels
|
|
|
|
fmt.Sscanf(input, format, &f, &i, &s)
|
|
fmt.Println("From the string we read: ", f, i, s) // From the string we read: 56.12 5212 Go
|
|
}
|