You need to break the scanning by passing EOF to the program.  Use ctrl-d 
if you're on Unix based system.

go doc bufio.Scan
func (s *Scanner) Scan() bool
    Scan advances the Scanner to the next token, which will then be 
available
    through the Bytes or Text method. It returns false when the scan stops,
    either by reaching the end of the input or an error. After Scan returns
    false, the Err method will return any error that occurred during 
scanning,
    except that if it was io.EOF, Err will return nil. Scan panics if the 
split
    function returns 100 empty tokens without advancing the input. This is a
    common error mode for scanners.



PS:  
1. Use fmt.Printf rather than fmt.Println to print output.
2. While posting code,  do format the code as its easier to read.

On Monday, 6 November 2017 13:29:58 UTC+5:30, 28911...@gmail.com wrote:
>
>   I am a beginning learner.there is a simple question about go,the program 
> is in the following:
> package main
>
> import (
>  "bufio"
>  "fmt"
>  "os"
> )
> func main() {
>  
>  counts := make(map[string]int)
>  input := bufio.NewScanner(os.Stdin)
>  for input.Scan() {
>   counts[input.Text()]++
>  }
>  for line, n := range counts {
>   if n > 1 {
>    fmt.Println("%d\t%s\n", n, line)
>   }
>  }
> }
>
> the question is how I input the number and get the output result??
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to