Question | Click to View Answer |
What does the following code print? package main
import "fmt"
func main() {
counter := 1
for counter < 4 {
fmt.Println("boats can float")
counter = counter + 1
}
}
|
The following three lines are printed: boats can float
boats can float
boats can float
|
What does the following code print? x := 6
x++
fmt.Println(x)
|
The |
What does the following code print? package main
import "fmt"
func main() {
for counter := 0; counter <= 2; counter++ {
fmt.Println("planes can fly")
}
}
|
The following three lines are printed: planes can fly
planes can fly
planes can fly
This This |
What does the following code print? sum := 0
nums := []int{2, 4, 6}
for _, num := range nums {
sum += num
}
fmt.Println(sum)
|
A |
What does the following code print? happy := []string{"sun", "flower", "bird"}
for index, w := range happy {
fmt.Println(index, ": The", w, "is happy")
}
|
The following lines are printed. 0 : The sun is happy
1 : The flower is happy
2 : The bird is happy
The If the |
What does the following code print? states := map[string]string{
"CA": "California",
"NY": "New York",
"AR": "Arkansas",
}
for k, v := range states {
fmt.Println(k, "is short for", v)
}
|
The following lines are printed. CA is short for California
NY is short for New York
AR is short for Arkansas
|