Created
July 13, 2017 21:20
-
-
Save jeffotoni/437a0ba17f462eb7afc617adf3fc98ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bufio" | |
| "fmt" | |
| "os" | |
| ) | |
| func main() { | |
| scanner := bufio.NewScanner(os.Stdin) | |
| var text string | |
| for text != "q" { // break the loop if text == "q" | |
| fmt.Print("digite algo:") | |
| scanner.Scan() | |
| text = scanner.Text() | |
| if text != "q" { | |
| fmt.Println("seu texto digitado: ", text) | |
| } | |
| } | |
| } |
Você também pode fazer assim:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
// obtém o que o usuário digitar
resp := bufio.NewScanner(os.Stdin)
for i := 1; i < 6; i++ {
fmt.Println("Digite algo: ")
resp.Scan()
fmt.Printf("Resposta %d =====> %s \n", i, resp.Text())
}
}Dessa forma também funciona:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
leitura := bufio.NewReader(os.Stdin)
fmt.Print("Sua Idade? ")
resposta, _ := leitura.ReadString('\n')
fmt.Println(resposta)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Você pode fazer desta forma...