package main
import (
"fmt"
"strconv"
"strings"
)
// Function to check if an integer includes a specific digit x times
func includesDigitXTimes(n int, digit rune, xtimes int) bool {
// Convert the integer to a string
str := strconv.Itoa(n)
// Count the occurrences of the specific digit
count := strings.Count(str, string(digit))
// Check if the count matches x
return count == xtimes
}
func main() {
number := 7097175
digit := '7'
xtimes := 3
if includesDigitXTimes(number, digit, xtimes) {
fmt.Printf("The number %d includes the digit '%c' exactly %d times.\n", number, digit, xtimes)
} else {
fmt.Printf("The number %d does not include the digit '%c' exactly %d times.\n", number, digit, xtimes)
}
}
/*
run:
The number 7097175 includes the digit '7' exactly 3 times.
*/