Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func main() {
- var num int
- fmt.Scanln(&num)
- if (num == 1) {
- fmt.Println("Monday")
- } else if (num == 2) {
- fmt.Println("Tuesday")
- } else if (num == 3) {
- fmt.Println("Wednesday")
- } else if (num == 4) {
- fmt.Println("Thursday")
- } else if (num == 5) {
- fmt.Println("Friday")
- } else if (num == 6) {
- fmt.Println("Saturday")
- } else if (num == 7) {
- fmt.Println("Sunday")
- } else {
- fmt.Println("Error")
- }
- }
- ИЛИ:
- package main
- import "fmt"
- func main() {
- var num int
- fmt.Scanln(&num)
- switch num {
- case 1:
- fmt.Println("Monday")
- case 2:
- fmt.Println("Tuesday")
- case 3:
- fmt.Println("Wednesday")
- case 4:
- fmt.Println("Thursday")
- case 5:
- fmt.Println("Friday")
- case 6:
- fmt.Println("Saturday")
- case 7:
- fmt.Println("Sunday")
- default:
- fmt.Println("Error")
- }
- }
- Решение с масив:
- package main
- import "fmt"
- func main() {
- var num int
- fmt.Scanln(&num)
- var dayOfWeek = []string {"Error", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
- if(num > 0 && num < len(dayOfWeek)) {
- fmt.Println(dayOfWeek[num])
- } else {
- fmt.Println(dayOfWeek[0])
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement