switch + random

언어/Go2016. 2. 26. 16:45
// switch
package main
import(
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
fmt.Print("switch example \n")
fmt.Print("SCORE INPUT >>> ")
var number int

number = rand.Intn(100)

fmt.Printf("%d\n", number)

switch number/10 {
case 1:
fmt.Println("one")
case 2:
fmt.Println("two")
case 3:
fmt.Println("three")
case 4:
fmt.Println("four")
case 5:
fmt.Println("five")
case 6:
fmt.Println("six")
case 7:
fmt.Println("seven")
case 8:
fmt.Println("eight")
case 9:
fmt.Println("nine")
default:
fmt.Printf("%d\n", number)
}
}


'언어 > Go' 카테고리의 다른 글

동작하기는 하는데 에러부분이 생긴다  (0) 2016.02.26
if문  (0) 2016.02.26
switch  (0) 2016.02.26
go언어 const  (0) 2016.02.20
stu1  (0) 2016.02.14