aprendago
aprendago copied to clipboard
Exercício: Capítulo 5, Exercício 6 (Nível: 2)
Exercício: Capítulo 5, Exercício 6 (Nível: 2)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!
https://play.golang.org/p/UDITIF9K2L1
https://play.golang.org/p/dbbkndgQPq3
https://play.golang.org/p/5JcMnLv50MF
Esse foi mais fácil, já q errei iota antes não considerando constante. Tentei var mas deu erro
package main
import ("fmt")
const (_ = iota
x = iota + 2020
y
t
b
)
func main(){
fmt.Println(x,y,t,b)
}
Massa esse iota.
package main
import (
"fmt"
)
const (
_ = iota + 2020
a
b
c
d
)
func main() {
fmt.Printf("Ano %d\nAno %d\nAno %d\nAno %d\n", a, b, c, d)
}
https://play.golang.org/p/BYwP0r2d3q-
https://play.golang.org/p/V8sUkQCKJYH
https://play.golang.org/p/y8BFLryB2Cg
package main
import "fmt"
const (
_ = 1994 + iota
b
c
d
e
)
func main() {
fmt.Println( b, c, d, e)
}
https://play.golang.org/p/JU-jP7bkXvk
https://play.golang.org/p/H2bWfkfhfwH
package main
import "fmt"
// Declara e atribui constantes cujos valores sejam os próximos 4 anos utilizando iota
const (
_ = 2021 + iota
primeiroAno
segundoAno
terceiroAno
quartoAno
)
func main() {
// Imprime as constantes
fmt.Println(primeiroAno, segundoAno, terceiroAno, quartoAno)
}
Output:
2022 2023 2024 2025
package main
//Utilizando iota, crie 4 constantes cujos valores sejam os próximos 4 anos demonstre estes valores.
import "fmt"
const (
_ = iota + 2021
ano2
ano3
ano4
ano5
)
func main() {
fmt.Print(ano2, ano3, ano4, ano5)
}
https://play.golang.org/p/vvgVkSy8EH5
package main
import "fmt"
const (
a = iota + 2021
b
c
d
)
func main(){
fmt.Println(a, b, c, d)
}
https://play.golang.org/p/wbRabpEQjzR
package main
import (
"fmt"
)
const (
_ = iota + 2021
a
b
c
d
)
func main() {
fmt.Println(a, b, c, d)
}
Output
2022 2023 2024 2025
https://go.dev/play/p/yQEbAN1eaFW
https://go.dev/play/p/NeqD1IQYOrE
package main
import "fmt"
func main() {
const (
_ = iota + 2022
a
b
c
d
)
fmt.Printf("%v\n%v\n%v\n%v\n", a, b, c, d)
}
const ( _ = 2023 + iota a b c d )
func main() { fmt.Println(a, b, c, d) }
https://go.dev/play/p/N86MdKOYKxO
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
type teste int
func main() {
const (
a = 2023 + iota
b
c
d
)
fmt.Println(a, b, c, d)
}
/*
- Utilizando iota, crie 4 constantes cujos valores sejam os próximos 4 anos.
- Demonstre estes valores.
*/
---------------------------------------------------------------------------------------------------------------------------------------------
2023 2024 2025 2026
Program exited.
---------------------------------------------------------------------------------------------------------------------------------------------
https://go.dev/play/p/9euEMjsRHym
https://go.dev/play/p/PUk10qO6Q_8
https://go.dev/play/p/KCwgviQ0MDX