Advertisement
Spocoman

01. Day of Week

Sep 17th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.40 KB | None | 0 0
  1. package main
  2. import "fmt"
  3.  
  4. func main() {
  5.     var num int
  6.     fmt.Scanln(&num)
  7.  
  8.     if (num == 1) {
  9.         fmt.Println("Monday")
  10.     } else if (num == 2) {
  11.         fmt.Println("Tuesday")
  12.     } else if (num == 3) {
  13.         fmt.Println("Wednesday")
  14.     } else if (num == 4) {
  15.         fmt.Println("Thursday")
  16.     } else if (num == 5) {
  17.         fmt.Println("Friday")
  18.     } else if (num == 6) {
  19.         fmt.Println("Saturday")
  20.     } else if (num == 7) {
  21.         fmt.Println("Sunday")
  22.     } else {
  23.         fmt.Println("Error")
  24.     }
  25. }
  26.  
  27. ИЛИ:
  28.  
  29. package main
  30. import "fmt"
  31.  
  32. func main() {
  33.     var num int
  34.     fmt.Scanln(&num)
  35.    
  36.     switch num {
  37.     case 1:
  38.         fmt.Println("Monday")
  39.     case 2:
  40.         fmt.Println("Tuesday")
  41.     case 3:
  42.         fmt.Println("Wednesday")
  43.     case 4:
  44.         fmt.Println("Thursday")
  45.     case 5:
  46.         fmt.Println("Friday")
  47.     case 6:
  48.         fmt.Println("Saturday")
  49.     case 7:
  50.         fmt.Println("Sunday")
  51.     default:
  52.         fmt.Println("Error")
  53.     }
  54. }
  55.  
  56. Решение с масив:
  57.  
  58. package main
  59. import "fmt"
  60.  
  61. func main() {
  62.     var num int
  63.     fmt.Scanln(&num)
  64.    
  65.     var dayOfWeek = []string {"Error", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
  66.    
  67.     if(num > 0 && num < len(dayOfWeek)) {
  68.         fmt.Println(dayOfWeek[num])
  69.     } else {
  70.         fmt.Println(dayOfWeek[0])
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement