Files
learngo/11-if/exercises/08-simplify-leap-year/solution/main.go
2019-10-30 19:41:13 +03:00

38 lines
873 B
Go

// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
package main
import (
"fmt"
"os"
"strconv"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Give me a year number")
return
}
year, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Printf("%q is not a valid year.\n", os.Args[1])
return
}
if year%4 == 0 && (year%100 != 0 || year%400 == 0) {
fmt.Printf("%d is a leap year.\n", year)
} else {
fmt.Printf("%d is not a leap year.\n", year)
}
}
// Review the original source code here:
// https://github.com/golang/go/blob/ad644d2e86bab85787879d41c2d2aebbd7c57db8/src/time/time.go#L1289