aprendago icon indicating copy to clipboard operation
aprendago copied to clipboard

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

Open vkorbes opened this issue 4 years ago • 17 comments

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!

vkorbes avatar Sep 30 '20 17:09 vkorbes

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

diegoparra avatar Oct 07 '20 19:10 diegoparra

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

andersoncleyson avatar Oct 09 '20 20:10 andersoncleyson

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

haystem avatar Nov 20 '20 02:11 haystem

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.

an4kein avatar Feb 18 '21 13:02 an4kein

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

alansantosmg avatar Apr 21 '21 02:04 alansantosmg

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

Lucasmirandar avatar Jun 09 '21 22:06 Lucasmirandar

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


JPauloMoura avatar Aug 08 '21 14:08 JPauloMoura

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

tomashugo avatar Oct 10 '21 15:10 tomashugo

`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)

} `

CaueFarias avatar Mar 15 '22 16:03 CaueFarias

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

viniciussanchez avatar Mar 17 '22 14:03 viniciussanchez

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

AlissonAp avatar Apr 15 '22 00:04 AlissonAp

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

wfrsilva avatar May 27 '22 02:05 wfrsilva

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)

}

M3L1M avatar Feb 13 '23 02:02 M3L1M

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

adelsonsljunior avatar May 13 '23 21:05 adelsonsljunior

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

DominMFD avatar May 15 '24 13:05 DominMFD

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

thiagoCalazans-dev avatar May 18 '24 11:05 thiagoCalazans-dev

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

Vitor-Zen avatar Jul 04 '24 14:07 Vitor-Zen