package main
import (
"bufio"
"fmt"
"os"
)
func main() {
in := bufio.NewReader(os.Stdin)
fmt.Println("Please input S: ")
S, _ := in.ReadString('
')
fmt.Println("Please input J: ")
J, _ := in.ReadString('
')
sum := numJewelsInStones(J,S)
fmt.Println(sum)
}
func numJewelsInStones(J string, S string) int {
var sum int
for _, s := range S {
for _, j := range J{
if s ==j {
sum ++
}
}
}
return sum
}
When I input "hello" and "h" at the terminal. This program will print 2, but except is 1.
And If i use fmt.Scanln(), the result will be 1.
What caused this result?