Jump to content

Find the last Sunday of each month: Difference between revisions

→‎{{header|Go}}: changed input method and typo
(→‎{{header|Go}}: changed input method and typo)
Line 529:
This is different from the Go code for [[Last Friday of each month]]. It uses the fact that time functions in Go correct for dates: if you enter 32nd of october, Go corrects to 1st of November. So that if 29th of February is corrected to 1st of March, chosen year is not a leap year.
 
<lang Gogo>package main
package main
 
import (
"fmt"
"bufio"
"os"
"time"
"strconv"
)
 
func main() {
var syearyear stringint
var year int64
var t time.Time
var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
for {
fmt.Print("Please select a year: ")
scanner := bufio.NewScanner(os.Stdin)
_, err := fmt.Scanf("%d", &year)
scanner.Split(bufio.ScanWords)
if err != nil {
for scanner.Scan () {
fmt.Println(err)
syear = scanner.Text()
continue
break
} else {
break
}
}
year, _ = strconv.ParseInt(syear, 0, 0)
 
fmt.Println("Last Sundays of each month of", year)
Line 577 ⟶ 574:
}
}
}
 
</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.