Added solutions

main
Victor Hans-Georg Waitz 2024-12-03 02:07:51 +01:00
parent 1ba83c27da
commit 2f0e5bc87b
6 changed files with 72 additions and 6 deletions

16
Aufgabe1/circle.go 100644
View File

@ -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)
}

View File

@ -1,6 +0,0 @@
package main
import "fmt"
//Idee: Wordcount nutzt forloops und bisschen logik

View File

@ -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);
}
}

View File

@ -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)
}

View File

@ -26,6 +26,11 @@ func main() {
fmt.Printf("%d + %d = %d \n", num2, num, result); 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!"; text := "Willkommen zu unserem Go Vortrag!";
words := strings.Fields(text); words := strings.Fields(text);