Giter Club home page Giter Club logo

Comments (13)

an4kein avatar an4kein commented on August 22, 2024 1

Demorei um pouco em utilizar o range de maneira correta, mas após  forçar  um pouco o cérebro e mais algumas pesquisas no Spec e Effective, muita tentativa e erro, cheguei no resultado pedido no exercício:

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

package main

import (
	"fmt"
)

var array = [5]int{}

func main() {
	fmt.Println(`Usando uma literal composta:`)
	fmt.Println("")

	fmt.Println(`- Crie um array que suporte 5 valores to tipo int: `)
	fmt.Println(array)
	array[0] = 1
	array[1] = 2
	array[2] = 1337
	array[3] = 345
	array[4] = 45353

	fmt.Println("")
	fmt.Println(`- Atribua valores aos seus índices`)

	for i, v := range array {
		fmt.Printf("Indice: %v => Valor: %v\n", i, v)
	}
	fmt.Println("")
	fmt.Println(`- Utilize range e demonstre os valores do array.`)

	for i := range array {
		fmt.Println(array[i])
	}

	fmt.Println("")
	fmt.Println(`- Utilizando format printing, demonstre o tipo do array.`)

	fmt.Printf("Type array: %T", array)

}

Output

Usando uma literal composta:

- Crie um array que suporte 5 valores to tipo int: 
[0 0 0 0 0]

- Atribua valores aos seus índices
Indice: 0 => Valor: 1
Indice: 1 => Valor: 2
Indice: 2 => Valor: 1337
Indice: 3 => Valor: 345
Indice: 4 => Valor: 45353

- Utilize range e demonstre os valores do array.
1
2
1337
345
45353

- Utilizando format printing, demonstre o tipo do array.
Type array: [5]int
Program exited.

from aprendago.

diegoparra avatar diegoparra commented on August 22, 2024

Fiquei um pouco na dúvida quanto a demonstrar os valores do array se isso deveria incluir mostrar os indexes tbm, então decidi só mostrar os valores atribuídos e não mostrar seus respectivos indexes.

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

from aprendago.

haystem avatar haystem commented on August 22, 2024

Fiquei confuso na parte de printar pq usei Printf em tudo. Saiu o resultado mas ficou ruim para ler, não entendia pq n ia com printf. Depois que voltei a explicação entendi que na parte que ele lê o valor ele ja traz em numero e não precisa do printf % para direcionar.

package main

import("fmt")

func main(){
  array := [5]int{1,2,3,4,5}
  
  for ind,valor := range array{
    fmt.Println(ind,valor)
  }
    fmt.Printf("%T",array)
}

from aprendago.

alansantosmg avatar alansantosmg commented on August 22, 2024
package main

import "fmt"

func main() {

	myArray := [5]int{0, 1, 2, 3, 4}

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

}

from aprendago.

Lucasmirandar avatar Lucasmirandar commented on August 22, 2024

https://play.golang.org/p/BuKA70b-mAf

from aprendago.

JPauloMoura avatar JPauloMoura commented on August 22, 2024

Crie um array que suporte 5 valores to tipo int, atribua valores aos seus índices, utilize range e demonstre os valores do array, Utilizando format printing demonstre o tipo do array..

package main

import "fmt"

func main() {
	arr := [4]int{10, 20, 30, 40}

	for i, v := range arr {
		fmt.Printf("Indíce %d: %d\n", i, v)
	}
	fmt.Printf("Tipo do array: %T", arr)
}

Resultado:

Indíce 0: 10
Indíce 1: 20
Indíce 2: 30
Indíce 3: 40
Tipo do array: [4]int%  

Resolução do Exercício


from aprendago.

tomashugo avatar tomashugo commented on August 22, 2024
package main

import (
	"fmt"
)

func main() {
	var array [5]int
	
	array[0] = 10
	array[1] = 20
	array[2] = 30
	array[3] = 40
	array[4] = 50
	
	for _, value := range array {
		fmt.Println(value)
	}
	
	fmt.Printf("%T\n",array)
}

from aprendago.

CaueFarias avatar CaueFarias commented on August 22, 2024

package main

import (
"fmt"
)

func main() {

array := [6]int{0, 1, 2, 3, 4, 5}

for índice, número := range array {

	fmt.Println("No índice", índice, "Temos o número: ", número)
}
fmt.Printf("%T", array)

}

from aprendago.

viniciussanchez avatar viniciussanchez commented on August 22, 2024

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

from aprendago.

AlissonAp avatar AlissonAp commented on August 22, 2024

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

from aprendago.

wfrsilva avatar wfrsilva commented on August 22, 2024

Cap. 9 – Exercícios: Nível #4 – 1
https://go.dev/play/p/SPZ9HDa5YGj

image

from aprendago.

M3L1M avatar M3L1M commented on August 22, 2024

func main() {
array := [5]int{1, 2, 3, 4, 5}

for indice, valor := range array {
	fmt.Println(indice, " - ", valor)
}

fmt.Printf("%T", array)

}

from aprendago.

adelsonsljunior avatar adelsonsljunior commented on August 22, 2024
package main

import (
	"fmt"
)

func main() {

	array := [5]int{1, 2, 3, 4, 5}
	for indice, valor := range array {
		fmt.Println(indice, valor)
	}
	fmt.Printf("%T", array)
}

from aprendago.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.