Section6.54
This commit is contained in:
33
Section6/54.go
Normal file
33
Section6/54.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
i, err := strconv.Atoi("45")
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
fmt.Println(i)
|
||||
}
|
||||
|
||||
if i, err := strconv.Atoi("20X"); err == nil { //20X can not be converted to int
|
||||
fmt.Println("No error, i is:", i)
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if args := os.Args; len(args) != 2 {
|
||||
fmt.Println("One argument is required")
|
||||
} else if km, err := strconv.Atoi(args[1]); err != nil {
|
||||
fmt.Println("The argument must be an integer! Error:", err)
|
||||
} else {
|
||||
fmt.Printf("%d km in miles is %v\n", km, float64(km)*0.621)
|
||||
fmt.Printf("%T\n", args[1])
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user