normalize printing

This commit is contained in:
Mark McGranaghan 2012-10-17 18:44:57 -07:00
parent 22f6542915
commit f79d9e151f

View File

@ -9,25 +9,25 @@ import "fmt"
// Here's a function that will take an arbitrary number
// of `ints` as arguments.
func sum(nums ...int) int {
func sum(nums ...int) {
fmt.Print(nums, " ")
total := 0
for _, num := range nums {
total += num
}
return total
fmt.Println(total)
}
func main() {
// Variadic functions can be called in the usual way
// with individual arguments.
fmt.Println(sum(1, 2))
fmt.Println(sum(1, 2, 3))
sum(1, 2)
sum(1, 2, 3)
// If you already have multiple args in a slice,
// apply them to a variadic function using
// `func(slice...)` like this.
nums := []int{1, 2, 3, 4}
fmt.Println(sum(nums...))
sum(nums...)
}