dart 中使用 stdin 输出数字的问题
带有数字的输出不起作用,我只能写第一个数字,之后应用程序将关闭。
void main(List<String> args) {
print("Escreva o numero de carros vendidos pelo funcionario ");
int nuyCar = stdin.readByteSync().toInt();
print("Escreva o salario fixo do funcionario: ");
double fixSalary = stdin.readByteSync().toDouble();
print("Escreva o valor arrecadado das vendas do funcionario: ");
double priceCollected = stdin.readByteSync().toDouble();
print(nuyCar);
print(fixSalary);
print(priceCollected);
}
The output with numbers does not work, I can only write the first number and after that the application closes.
void main(List<String> args) {
print("Escreva o numero de carros vendidos pelo funcionario ");
int nuyCar = stdin.readByteSync().toInt();
print("Escreva o salario fixo do funcionario: ");
double fixSalary = stdin.readByteSync().toDouble();
print("Escreva o valor arrecadado das vendas do funcionario: ");
double priceCollected = stdin.readByteSync().toDouble();
print(nuyCar);
print(fixSalary);
print(priceCollected);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,Dart 是严重依赖空检查的语言之一。在这里阅读更多相关信息 -> https://dart.dev/null-safety
您应该养成检查这些的习惯。此外,您还可以使用
readLineSync()
,而不是readBytes()
。你的程序可以这样写:
Well, Dart is one of those languages that heavily relies on null-checks. Read more about it here -> https://dart.dev/null-safety
You should get in habit of checking for those. Also, instead of
readBytes()
, you can usereadLineSync()
.Your program could be written as such: