首页 > 解决方案 > go中符文文字中的多个字符

问题描述

我是新来的。我的问题是得到奇数。但我得到这个错误。我不知道你能解释一下我犯了什么错误吗?

package main
import "fmt"

func main(){
    var a int 
    fmt.Printf("Enter the number : ")
    fmt.Scanf('%d', &a)

    if a % 2==0{
        fmt.Println(" %d Is even number", a)
    }else{
        fmt.Println( "%d is odd number", a)
    }
}

标签: go

解决方案


更改'%d'"%d"

在 Go中,单引号用于符文文字

'a'
'ä'
'本'
'\t'
'\000'
'\007'
'\377'
'\x07'
'\xff'
'\u12e4'
'\U00101234'
'\''         // rune literal containing single quote character
'aa'         // illegal: too many characters
'\xa'        // illegal: too few hexadecimal digits
'\0'         // illegal: too few octal digits
'\uDFFF'     // illegal: surrogate half
'\U00110000' // illegal: invalid Unicode code point

双引号和反引号用于字符串文字

`abc`                // same as "abc"
`\n
\n`                  // same as "\\n\n\\n"
"\n"
"\""                 // same as `"`
"Hello, world!\n"
"日本語"
"\u65e5本\U00008a9e"
"\xff\u00FF"
"\uD800"             // illegal: surrogate half
"\U00110000"         // illegal: invalid Unicode code point

推荐阅读