24 lines
372 B
Go
24 lines
372 B
Go
// Correct solution: prints the sum of the integers on standard input.
|
|
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
func main() {
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
scanner.Split(bufio.ScanWords)
|
|
total := 0
|
|
for scanner.Scan() {
|
|
value, err := strconv.Atoi(scanner.Text())
|
|
if err != nil {
|
|
os.Exit(2)
|
|
}
|
|
total += value
|
|
}
|
|
fmt.Println(total)
|
|
}
|