gpt4 book ai didi

dart - 使用Dart出现此小错误

转载 作者:行者123 更新时间:2023-12-03 03:43:38 26 4
gpt4 key购买 nike

import 'dart:io';

void main() {
double base = 1, bnry = 0, remainder = 0, ans = 0, inp;
print("Please input binary number : ");
inp = stdin.readLineSync();
bnry = inp;
while(inp < 1){
remainder = inp % 10;
ans = ans + remainder * base;
base = base * 2;
inp = inp / 10;
}
print("$inp");
}

这是我的代码,这是错误消息

unhandled exception: Class 'String' has no instance method '<'. NoSuchMethodError: method not found: '<'

最佳答案

您从stdin.readLineSync()获得一个字符串。您需要将其转换为数字才能与其他数字进行比较

inp = num.parse(stdin.readLineSync());

关于dart - 使用Dart出现此小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37052942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com