diff --git a/Section11/89-1.go b/Section11/89-1.go new file mode 100644 index 0000000..e463c57 --- /dev/null +++ b/Section11/89-1.go @@ -0,0 +1,21 @@ +/* +Coding Exercise #1 + +Using a composite literal declare and initialize +a slice of type string with 3 elements. + +Iterate over the slice and print each element in +the slice and its index. +*/ + +package main + +import "fmt" + +func main() { + countries := []string{"Romania", "Brazil", "Germany"} + for i, v := range countries { + fmt.Printf("Index: %d, Element: %q\n", i, v) + } + +} diff --git a/Section11/89-2.go b/Section11/89-2.go new file mode 100644 index 0000000..dfa9e6a --- /dev/null +++ b/Section11/89-2.go @@ -0,0 +1,45 @@ +/* +Coding Exercise #2 + +There are some errors in the following Go program. Try to identify the errors, +change the code and run the program without errors. + + package main + + import "fmt" + + func main() { + mySlice := []float64{1.2, 5.6} + + mySlice[2] = 6 + + a := 10 + mySlice[0] = a + + mySlice[3] = 10.10 + + mySlice = append(mySlice, a) + + fmt.Println(mySlice) + + } +*/ +package main + +import "fmt" + +func main() { + mySlice := []float64{1.2, 5.6} + + mySlice[1] = 6 + + a := 10 + mySlice[0] = float64(a) + + mySlice[1] = 10.10 + + mySlice = append(mySlice, float64(a)) + + fmt.Println(mySlice) + +} diff --git a/Section11/89-3.go b/Section11/89-3.go new file mode 100644 index 0000000..641a91b --- /dev/null +++ b/Section11/89-3.go @@ -0,0 +1,17 @@ +/* +Coding Exercise #3 + +1. Declare a slice called nums with three float64 numbers. + +2. Append the value 10.1 to the slice + +3. In one statement append to the slice the values: 4.1, 5.5 and 6.6 + +4. Print out the slice + +5. Declare a slice called n with two float64 values + +6. Append n to nums + +7. Print out the nums slice +*/