vkorbes / aprendago

Curso completo em português da linguagem Go, de zero a ninja! 🇧🇷
http://aprendago.com
1k stars 179 forks source link

Exercício: Capítulo 9, Exercício 2 (Nível: 4) #28

Open vkorbes opened 3 years ago

vkorbes commented 3 years ago

Exercício: Capítulo 9, Exercício 2 (Nível: 4)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

diegoparra commented 3 years ago

https://play.golang.org/p/Xmuf4-dSlDE

andersoncleyson commented 3 years ago

https://play.golang.org/p/u24rA4vhu4C

haystem commented 3 years ago

fiz com strings e printf

package main

import("fmt")

func main(){
 array := [10]string{"Ana","Joana","Siraya","Carla","Vivian","Betina","Laritssa","Bianca","Muana","Juressica"} 

  for indice, valor:= range array{
    fmt.Printf("%d, %s \n", indice, valor)
  }
  fmt.Printf("%T",array)
}
an4kein commented 3 years ago

https://play.golang.org/p/_pKZB7SlqC7

package main

import (
    "fmt"
)

func main() {
    fmt.Println(`Usando uma literal composta:`)
    fmt.Println("")
    slice := []int{}
    fmt.Printf("- Crie uma slice de tipo int:")
    fmt.Println("")
    fmt.Printf("%T", slice)
    fmt.Println("")
    fmt.Println("")

    fmt.Printf("- Atribua 10 valores a ela: \n")
    slice = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    fmt.Println(slice)
    fmt.Println("")

    fmt.Printf("- Utilize range para demonstrar todos estes valores.\n")
    for v := range slice {
        fmt.Println(slice[v])
    }
    fmt.Println("")
    fmt.Printf("- E utilize format printing para demonstrar seu tipo.\n")
    fmt.Printf("Type of slice: %T", slice)
}

Output

Usando uma literal composta:

- Crie uma slice de tipo int:
[]int

- Atribua 10 valores a ela: 
[1 2 3 4 5 6 7 8 9 10]

- Utilize range para demonstrar todos estes valores.
1
2
3
4
5
6
7
8
9
10

- E utilize format printing para demonstrar seu tipo.
Type of slice: []int
Program exited.
alansantosmg commented 3 years ago
package main

import "fmt"

func main() {

    umaSlice := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

    for _, v := range umaSlice {
        fmt.Printf("%v ", v)
    }

    fmt.Printf("%T", umaSlice)
}
Lucasmirandar commented 3 years ago

https://play.golang.org/p/oW-soISfjuE

JPauloMoura commented 2 years ago

2. Crie uma Slice do tipo int, atribua 10 valores a ela, utilize range para demonstrar todos estes valores, e utilize format printing para demonstrar seu tipo.

package main

import "fmt"

func main() {
    slice := []int{0, 10, 20, 30, 40, 50, 70, 80, 90, 100}
    for i, v := range slice {
        fmt.Printf("Indíce  %d: %d\n", i, v)
    }
    fmt.Printf("Tipo do slice: %T", slice)
}

Resultado:

Indíce  0: 0
Indíce  1: 10
Indíce  2: 20
Indíce  3: 30
Indíce  4: 40
Indíce  5: 50
Indíce  6: 70
Indíce  7: 80
Indíce  8: 90
Indíce  9: 100
Tipo do slice: []int  

Resolução do Exercício


tomashugo commented 2 years ago
package main

import (
    "fmt"
)

func main() {
    slice := [10]int{1,2,3,4,5,6,7,8,9,10}

    for key, value := range slice {
        fmt.Printf("Índice: %v, Valor: %v\n",key, value)
    }

    fmt.Printf("%T\n",slice)
}
CaueFarias commented 2 years ago

`package main

import ( "fmt" )

func main() {

slice := []int{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}

for índice, número := range slice {
    fmt.Println("No índice: ", índice, "Temos o valor: ", número)
}
fmt.Printf("%T", slice)

} `

viniciussanchez commented 2 years ago

https://go.dev/play/p/v193psTiVEf

AlissonAp commented 2 years ago

https://go.dev/play/p/oa3YJ50-7_7

wfrsilva commented 2 years ago

Cap. 9 – Exercícios: Nível #4 – 2 https://go.dev/play/p/DWOFNp-oj1N image

M3L1M commented 1 year ago

func main() { slice := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

for indice, valor := range slice {
    fmt.Printf("%v - %v\n", indice, valor)
}

fmt.Printf("%T", slice)

}

adelsonsljunior commented 1 year ago
package main

import (
    "fmt"
)

func main() {

    slice := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    for indice, valor := range slice {
        fmt.Println(indice, valor)
    }
    fmt.Printf("%T", slice)
}
DominMFD commented 2 months ago

https://go.dev/play/p/ZinSUU8LHEu

thiagoCalazans-dev commented 2 months ago

https://go.dev/play/p/gjbZogaeCeM

Vitor-Zen commented 3 weeks ago

https://go.dev/play/p/w88tZmGewVB