小编Rah*_*rma的帖子

在 Solidity 中,keccak 256 函数返回一个哈希值。keccak 256 返回多少位?

我使用了以下命令:keccak256('abc', 'pqr', 123); 一旦我运行它,我就会得到一个值。这是多少位值?

keccak solidity

6
推荐指数
1
解决办法
9253
查看次数

当 switch case 出现错误时如何让 switch 语句起作用

根据命令行中的用户输入,switch case 返回整数的评级。由于命令行参数是字符串类型,我首先将其转换为字符串int,然后在 switch 中使用它。

package main

import (
  "fmt"
  "os"
  "reflect"
  "strconv"
)

func main() {
 rating, _ := strconv.Atoi(os.Args[1])
 fmt.Println(reflect.TypeOf(rating))
 switch rating {
  case rating >= 2100:
    fmt.Println("grand master")
  case rating >= 1900:
    fmt.Println("candidate master")
  case rating >= 1600:
    fmt.Println("expert")
  case rating >= 1400:
    fmt.Println("pupil")
  case rating < 1400:
    fmt.Println("newbie")
  }

}
Run Code Online (Sandbox Code Playgroud)

现在,对于所有比较而言,评级 >= 2100 时都会出现错误。其过程如下:

cannot convert rating >= 2100 (untyped bool value) to intcompilerInvalidUntypedConversion
Run Code Online (Sandbox Code Playgroud)

无法理解如何解决这个问题。

请帮忙!

go switch-statement

1
推荐指数
1
解决办法
3273
查看次数

标签 统计

go ×1

keccak ×1

solidity ×1

switch-statement ×1