Yellow Submarine

Report a typo

You're given a line from the song; return the number of words in it.

Tip: The built-in function len returns the length of a slice.

Write a program in Go
package main

import (
"fmt"
"os"
"bufio"
"strings"
)

func numberOfWords(line string) int {
return len(?) // number of words
}

// DO NOT EDIT
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
fmt.Println(numberOfWords(scanner.Text()))
}
___

Create a free account to access the full topic