vkorbes / aprendago

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

Exercício: Capítulo 3, Exercício 4 (Nível: 1) #7

Open vkorbes opened 4 years ago

vkorbes commented 4 years ago

Exercício: Capítulo 3, Exercício 4 (Nível: 1)

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 4 years ago

solução: https://play.golang.org/p/DE9KugzYlxP

rodrimor commented 3 years ago

Solução tipo numerinho

haystem commented 3 years ago

Usei a referencia do link para relembrar Minha solução:

package main 

import (
  "fmt"
  )

  type laranjas int8
  var x laranjas
  func main (){
    x = 42

    fmt.Printf("O valor de X: %v do tipo %T.",x,x)

  }
yurimorales commented 3 years ago

Segue abaixo o código desenvolvido:

package main

import "fmt"

type modelo int

var x modelo

func main() { fmt.Printf("%v, %T\n", x, x) x = 42 fmt.Printf("Valor da variável x, após a atribuição: %v", x) }

guifeliper commented 3 years ago

Massa 🚀

package main

import (
    "fmt"
)
type numeros int
var x numeros

func main() {
    fmt.Printf("O valor de X é %d do tipo %T\n", x, x)
    x = 42
    fmt.Printf("Agora o valor de X é %d do tipo %T\n", x, x)
}
Julian-ie commented 3 years ago

https://play.golang.org/p/pokOsz-6C3w

viniciussanchez commented 3 years ago

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

viniciussanchez commented 3 years ago

@haystem o exercício pede que antes de atribuir o valor 42 a variável X, seja exibido o seu valor 0 e também seu tipo. Depois faça a atribuição e mostre novamente seu valor ;)

thiagoalgo commented 3 years ago

https://play.golang.org/p/6RaQrefQbjA

wesleydutrads commented 3 years ago

https://play.golang.org/p/5UwNuNrkdf6

vnessaethi commented 3 years ago
package main

import "fmt"

type testetipo int

var x testetipo

func main() {
    fmt.Printf("O valor de x é: %v\n", x)
    fmt.Printf("O tipo de x é: %T\n\n", x)

    x = 42
    fmt.Println("Agora o valor de x é: ", x)
}
victorinno commented 3 years ago

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

ygorsimoes commented 3 years ago
package main

import "fmt"

// Cria um tipo onde o tipo subjacente é int
type exemploTipo int

// Cria uma variável com o tipo criado acima
var x exemploTipo

func main() {

    // Imprime o valor da variável
    fmt.Println(x)

    // Imprime o tipo da variável
    fmt.Printf("%T\n", x)

    // Atribui o valor 42 a variável
    x = 42

    // Imprime novamente o valor da variável
    fmt.Println(x)
}

Output:

0
main.exemploTipo
42
exageraldo commented 3 years ago

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

isonux commented 3 years ago

package main

import ( "fmt" )

type conteiner int

var x conteiner

func main() {

    // Para imprimir o valor e o tipo da variável eu demorei para sacar que era
    // necessário passar a variável duas vezes no fmt.Printf 
fmt.Printf("%v\n%T", x,x)
x = 42
fmt.Printf("\n%v", x)

}

abeswz commented 3 years ago
package main

import "fmt"

type meonly int

var x meonly

func main() {
    fmt.Printf("%v typeof %T\n", x, x)
    x = 42
    fmt.Printf("%v typeof %T", x, x)
}
vinicius-henrique-araujo commented 3 years ago

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

andersoncleyson commented 3 years ago

Entendi dessa forma:

package main

import "fmt"

type tipo int

var x tipo 

func main(){
    fmt.Printf("%v %T\n", x, x)
    x = 42
    fmt.Printf("%v %T\n", x, x)
}
0 main.tipo
42 main.tipo
leesxs commented 3 years ago

O meu ficou assim: https://play.golang.org/p/Bc-P9LyWAzl

Me enrolei um pouco com o fmt.Printf e fmt.Println, mas no final deu tudo certo!

guilherme-de-marchi commented 3 years ago
package main

import "fmt"

type bilada int

var x bilada

func main() {

    fmt.Printf("Variável: x | Tipo: %T | Biladas(valor): %v \n", x, x)

    x = 42

    fmt.Printf("Variável: x | Tipo: %T | Biladas(valor): %v \n", x, x)

}

Output:

Variável: x | Tipo: main.bilada | Biladas(valor): 0 
Variável: x | Tipo: main.bilada | Biladas(valor): 42 
leolucena22 commented 2 years ago
package main

import "fmt"

type meuTipo int

var x meuTipo

func main() {
    fmt.Printf("Valor: %v \nTipo: %T\n", x, x)
    x = 42
    fmt.Println(x)
}

Output

╭─leonardo@arch ~/Projects/go/curso ‹main*› 
╰─$ go run ./04.go
Valor: 0 
Tipo: main.meuTipo
42
KevenMarioN commented 2 years ago

type cart int

var x cart

func main() { fmt.Printf("%v, %T\n",x,x) x = 42 fmt.Printf("%v\n",x)

}

### Saída

0, main.cart 42

CarlosSMA commented 2 years ago
package main

import (
    "fmt"
)

// Criação subtipo int
type subtype int

// Criação da variável x com palavra-chave "var"
var x subtype

func main() {
    fmt.Printf("Valor: %v\n", x)
    fmt.Printf("Tipo: %T\n", x)
    x = 42
    fmt.Printf("Valor: %v\n", x)
}

[Dicas] Saber quando usar Print/Println ao invés de Printf("%v")

ltbatis commented 2 years ago

https://play.golang.org/p/3bbMTf5UMZS

AlissonAp commented 2 years ago

https://go.dev/play/p/9L8F3ndmokQ

gustavomfc commented 2 years ago

// You can edit this code! // Click here and start typing. package main

import "fmt"

type bora int

var x bora

func main() { fmt.Printf("Valor inicial de X: %v\n", x)

x = 42

fmt.Printf("Valor final de X após atribuição: %v\n", x)

}

GabriewF commented 2 years ago

Code:

// Main Package
package main

// Import of the packages
import (
    "fmt"
)

// Package-level scope variables
var ()

// Typings
type hotdog int

// Main function
func main() {
    // Code-scope variables
    var (
        x hotdog
    )

    // Show the value of the variable "X"
    fmt.Printf("Value of X: %v\n", x)

    // Show the type of variable "X"
    fmt.Printf("Type of X: %T\n", x)

    // Assign 42 to the variable "X" using the "=" operator
    x = 42

    // Show the value of the variable "X"
    fmt.Printf("Value of X: %v", x)
}

Output:

Value of X: 0
Type of X: main.hotdog
Value of X: 42

Link to Go Playground

kayquecoelho commented 2 years ago

https://go.dev/play/p/YfNnHP-V85S

fennder commented 1 year ago

// You can edit this code! // Click here and start typing. package main

import "fmt"

type abrindo int

var x abrindo

func main() {

fmt.Printf("%v\t%T\t\n", x, x)
x = 42
fmt.Println(x)

}

M3L1M commented 1 year ago

type inteiro int

var x inteiro

func main() { fmt.Printf("%d\t%T\n", x, x) x = 47 fmt.Print(x) }

an4kein commented 1 year ago

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

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

type anak int

var x anak

func main() {
    fmt.Println(x)
    fmt.Printf("%T\n", x)
    x = 42
    fmt.Printf("%v", x)
}
-----------------------------------------------------------------------------------------------------------------------------------------------
Output

0
main.anak
42
Program exited.
-----------------------------------------------------------------------------------------------------------------------------------------------
/*
- Crie um tipo. O tipo subjacente deve ser int.
- Crie uma variável para este tipo, com o identificador "x", utilizando a palavra-chave var.
- Na função main:
    1. Demonstre o valor da variável "x"
    2. Demonstre o tipo da variável "x"
    3. Atribua 42 à variável "x" utilizando o operador "="
    4. Demonstre o valor da variável "x"
*/
adelsonsljunior commented 1 year ago
package main

import (
    "fmt"
)

type algumTipo int

var x algumTipo

func main() {

    fmt.Printf("%v", x)
    fmt.Printf("\n%T", x)
    x = 42
    fmt.Printf("\n%v", x)

}
uiltonlopes commented 1 year ago

https://go.dev/play/p/9WPEPyiMGIX

hiercj commented 5 months ago

https://goplay.tools/snippet/clsSwNzSbDa

Screenshot 2024-04-12 174219

1r4mos commented 5 months ago

https://goplay.tools/snippet/lU68bdsa-RY

DominMFD commented 4 months ago

https://go.dev/play/p/KUqdvrp8cF-

raingrave commented 4 months ago

https://go.dev/play/p/6B8belGBYZ2

RickLinuux commented 3 months ago
package main

import "fmt"

type xpto int

var x xpto

func main() {
    fmt.Printf("%v\n", x)
    fmt.Printf("%T\n", x)
    x = 42
    fmt.Println(x)
}
Vitor-Zen commented 3 months ago

https://go.dev/play/p/6oFKHnXM8RM

Hzin commented 2 weeks ago
package main

import "fmt"

type newType int

var x newType

func main() {
    fmt.Printf("Valor de x=%v\n", x)
    fmt.Printf("Tipo de x=%T\n", x)

    x = 42
    fmt.Printf("Valor de x atualizado=%v", x)
}
vorthkor commented 5 days ago

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