@ -0,0 +1,27 @@ | |||||
package main | |||||
import "fmt" | |||||
func main() { | |||||
words := map[string]int{ | |||||
"Gonna": 3, | |||||
"You": 3, | |||||
"Give": 2, | |||||
"Never": 1, | |||||
"Up": 4, | |||||
} | |||||
max_word := "" | |||||
max_count := 0 | |||||
for word, count := range words { | |||||
if count > max_count { | |||||
max_word, max_count = word, count | |||||
} | |||||
} | |||||
fmt.Println("Most popular word:", max_word) | |||||
fmt.Println("With a count of:", max_count) | |||||
} |
@ -0,0 +1,23 @@ | |||||
package main | |||||
import "fmt" | |||||
func main() { | |||||
numbers := []int{5, 8, 2, 4, 0, 1, 3, 7, 9, 6} | |||||
fmt.Println("Before:", numbers) | |||||
for swapped := true; swapped == true; { | |||||
swapped = false | |||||
for i := 1; i < len(numbers); i++ { | |||||
if numbers[i] < numbers[i-1] { | |||||
numbers[i-1], numbers[i] = numbers[i], numbers[i-1] | |||||
swapped = true | |||||
} | |||||
} | |||||
} | |||||
fmt.Println("After: ", numbers) | |||||
} |
@ -0,0 +1,30 @@ | |||||
package main | |||||
import ( | |||||
"fmt" | |||||
"time" | |||||
) | |||||
func main() { | |||||
dayBorn := time.Monday | |||||
switch dayBorn { | |||||
case time.Monday: | |||||
fmt.Println("Monday's child is fair of face") | |||||
case time.Tuesday: | |||||
fmt.Println("Tuesday's child is full of grace") | |||||
case time.Wednesday: | |||||
fmt.Println("Wednesday's child is fair of woe") | |||||
case time.Thursday: | |||||
fmt.Println("Thursday's child has far to go") | |||||
case time.Friday: | |||||
fmt.Println("Friday's child is loving and giving") | |||||
case time.Saturday: | |||||
fmt.Println("Saturday's child works hard for a living") | |||||
case time.Sunday: | |||||
fmt.Println("Sunday's child is bonny and blithe") | |||||
default: | |||||
fmt.Println("Error, day born not valid") | |||||
} | |||||
} |
@ -0,0 +1,22 @@ | |||||
package main | |||||
import ( | |||||
"fmt" | |||||
"time" | |||||
) | |||||
func main() { | |||||
dayBorn := time.Sunday | |||||
switch dayBorn { | |||||
case time.Monday, time.Tuesday, time.Wednesday, | |||||
time.Thursday, time.Friday: | |||||
fmt.Println("Gorn on a weekday") | |||||
case time.Saturday, time.Sunday: | |||||
fmt.Println("Born on the weekend") | |||||
default: | |||||
fmt.Println("Error, day born not valid") | |||||
} | |||||
} |
@ -0,0 +1,17 @@ | |||||
package main | |||||
import ( | |||||
"fmt" | |||||
"time" | |||||
) | |||||
func main() { | |||||
switch dayBorn := time.Sunday; { | |||||
case dayBorn == time.Saturday || dayBorn == time.Sunday: | |||||
fmt.Println("Born on the weekend") | |||||
default: | |||||
fmt.Println("Born some other day") | |||||
} | |||||
} |
@ -0,0 +1,11 @@ | |||||
package main | |||||
import "fmt" | |||||
func main() { | |||||
for i := 0; i < 5; i++ { | |||||
fmt.Println(i) | |||||
} | |||||
} |
@ -0,0 +1,13 @@ | |||||
package main | |||||
import "fmt" | |||||
func main() { | |||||
names := []string{"Jim", "Jane", "Joe", "June"} | |||||
for i := 0; i < len(names); i++ { | |||||
fmt.Println(names[i]) | |||||
} | |||||
} |
@ -0,0 +1,17 @@ | |||||
package main | |||||
import "fmt" | |||||
func main() { | |||||
config := map[string]string{ | |||||
"debug": "1", | |||||
"logLevel": "warn", | |||||
"version": "1.2.1", | |||||
} | |||||
for key, value := range config { | |||||
fmt.Println(key, "=", value) | |||||
} | |||||
} |
@ -0,0 +1,22 @@ | |||||
package main | |||||
import ( | |||||
"fmt" | |||||
"math/rand" | |||||
) | |||||
func main() { | |||||
for { | |||||
r := rand.Intn(8) | |||||
if r%3 == 0 { | |||||
fmt.Println("Skip") | |||||
continue | |||||
} else if r%2 == 0 { | |||||
fmt.Println("Stop") | |||||
break | |||||
} | |||||
fmt.Println(r) | |||||
} | |||||
} |