Added solutions
parent
1ba83c27da
commit
2f0e5bc87b
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
type Circle struct {
|
||||
radius float64
|
||||
}
|
||||
|
||||
func main() {
|
||||
circle := Circle{radius: 6.4}
|
||||
circumference := 2 * math.Pi * circle.radius
|
||||
fmt.Println(circumference)
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
//Idee: Wordcount nutzt forloops und bisschen logik
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fruits := "ananas orange apfel apfel\n aprikose kirche"
|
||||
|
||||
words := strings.Split(fruits, " ")
|
||||
|
||||
wordCount := make(map[string]int)
|
||||
|
||||
for _, word := range words {
|
||||
word = strings.ReplaceAll(word, "\n", ""); // Wenn man newlines entfernen will
|
||||
if strings.HasPrefix(word, "a") {
|
||||
wordCount[word]++
|
||||
}
|
||||
}
|
||||
|
||||
for word, count := range wordCount {
|
||||
fmt.Printf("%T: %v \n", word, count);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func count(start, end int, ch chan int) {
|
||||
for i := start; i <= end; i++ {
|
||||
ch <- i
|
||||
}
|
||||
}
|
||||
|
||||
func printCh(ch chan int) {
|
||||
for i := 0; i < 10; i++ {
|
||||
fmt.Println(<-ch)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
channel1to5 := make(chan int)
|
||||
channel6to10 := make(chan int)
|
||||
|
||||
go count(1, 10, channel1to5)
|
||||
go count(6, 10, channel6to10)
|
||||
|
||||
printCh(channel1to5)
|
||||
printCh(channel6to10)
|
||||
}
|
|
@ -26,6 +26,11 @@ func main() {
|
|||
|
||||
fmt.Printf("%d + %d = %d \n", num2, num, result);
|
||||
|
||||
for i := 0; i <= 6; i++ { // Alle Zahlen von 0 - 6
|
||||
if i%2 == 0 { // Filtert nach gerade Zahlen
|
||||
fmt.Println(i);
|
||||
}
|
||||
}
|
||||
|
||||
text := "Willkommen zu unserem Go Vortrag!";
|
||||
words := strings.Fields(text);
|
Loading…
Reference in New Issue