Open vkorbes opened 4 years ago
Solução tipo numerinho
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)
}
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) }
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)
}
@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 ;)
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)
}
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
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)
}
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)
}
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
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!
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
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)
}
╭─leonardo@arch ~/Projects/go/curso ‹main*›
╰─$ go run ./04.go
Valor: 0
Tipo: main.meuTipo
42
import (
"fmt"
)
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
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")
// 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)
}
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
// 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)
}
type inteiro int
var x inteiro
func main() { fmt.Printf("%d\t%T\n", x, x) x = 47 fmt.Print(x) }
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"
*/
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)
}
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)
}
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)
}
Exercício: Capítulo 3, Exercício 4 (Nível: 1)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!