Skip to content

Instantly share code, notes, and snippets.

@xvbnm48
Created March 8, 2022 16:01
Show Gist options
  • Save xvbnm48/111971b18820977c4f140932827de023 to your computer and use it in GitHub Desktop.
Save xvbnm48/111971b18820977c4f140932827de023 to your computer and use it in GitHub Desktop.
package main
import (
"errors"
"fmt"
"strconv"
"strings"
)
func main(){
var input string
fmt.Println("Enter some number: ")
fmt.Scanln(&input)
var number int
var err error
number, err = strconv.Atoi(input)
if err == nil {
fmt.Println(number, " is number")
} else {
fmt.Println(input, " is not number")
fmt.Println(err.Error())
}
}
// jika hasilnya error
//Enter some number:
//k
// k is not number
// strconv.Atoi: parsing "k": invalid syntax
// jika benar
// Enter some number:
// 1
// 1 is number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment