mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 22:06:51 +08:00
@@ -81,7 +81,6 @@ input, err := inputReader.ReadString('\n')
|
|||||||
第二个例子从键盘读取输入,使用了 `switch` 语句:
|
第二个例子从键盘读取输入,使用了 `switch` 语句:
|
||||||
|
|
||||||
**Listing 12.3—switch_input.go:**
|
**Listing 12.3—switch_input.go:**
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
import (
|
import (
|
||||||
@@ -123,25 +122,22 @@ func main() {
|
|||||||
default: fmt.Printf("You are not welcome here! Goodbye!\n")
|
default: fmt.Printf("You are not welcome here! Goodbye!\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
注意:Unix和Windows的行结束符是不同的!
|
注意:Unix和Windows的行结束符是不同的!
|
||||||
|
|
||||||
**练习**
|
**练习**
|
||||||
|
|
||||||
**Exercise 12.1:** word_letter_count.go
|
**练习 12.1:** word_letter_count.go
|
||||||
Write a program which reads text from the keybord. When the user enters ‘S’ in order to signal the end of the input, the program shows 3 numbers:
|
编写一个程序,从键盘读取输入。当用户输入 'S' 的时候表示输入结束,这时程序输出 3 个数字:
|
||||||
i) the number of characters including spaces (but excluding ‘\r’ and ‘\n’)
|
i) 输入的字符的个数,包括空格,但不包括 '\r' 和 '\n'
|
||||||
ii) the number of words
|
ii) 输入的单词的个数
|
||||||
iii) the number of lines
|
iii) 输入的行数
|
||||||
|
|
||||||
**Exercise 12.2:** calculator.go
|
**练习 12.2:** calculator.go
|
||||||
Make a simple (reverse polish notation) calculator. This program accepts input from the user in the
|
编写一个简单的逆波兰式计算器,它接受用户输入的整型数(最大值 999999)和运算符 +、-、*、/。
|
||||||
form of integers (maximum 999999) and operators (+, -, *, /).
|
输入的格式为:number1 ENTER number2 ENTER operator ENTER --> 显示结果
|
||||||
|
当用户输入字符 'q' 时,程序结束。请使用您在练习11.3中开发的 `stack` 包。
|
||||||
The input is like this: number1 ENTER number2 ENTER operator ENTER result is displayed.
|
|
||||||
|
|
||||||
The programs stops if the user inputs “q”. Use the package stack you developed in Ex. 11.3
|
|
||||||
|
|
||||||
|
|
||||||
## 链接
|
## 链接
|
||||||
|
Reference in New Issue
Block a user