首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在我使用stdin和随机的飞镖码上的错误

在我使用stdin和随机的飞镖码上的错误
EN

Stack Overflow用户
提问于 2022-04-25 15:04:20
回答 1查看 84关注 0票数 0

未处理的异常: NoSuchMethodError:类'String‘没有实例方法'<’。接收方:"5“尝试调用:<(44) #0 (file:///C:/Users/LOGO%20CS/IdeaProjects/oop%205/bin/oop_5.dart:20:18) ( Object.noSuchMethod :核心补丁/object_patch.dart:38:5) #1 guessWithPC.run #2主Object.noSuchMethod #3 _delayEntrypointInvocation。(dart:isolate-patch/isolate_patch.dart:297:19) #4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

使用退出代码255完成的处理

代码语言:javascript
复制
import 'dart:io';
import 'dart:math';
class guessWithPC{
  var userGuess;
  var computerGuess;
  var number;
  guessWithPC(){
    Random random;
    random =Random();
    number = random.nextInt(50);
    print('guess the number');

  }
run(){
    Random random;
    random =Random();
  userGuess = stdin.readLineSync();
  int.parse(userGuess);
  computerGuess = random.nextInt(50);
    if(userGuess < number ) {
      print('less then true');
    }
      print(computerGuess);
      if(computerGuess < number ){
        print(' computer guessed less then true');
      }
    if(userGuess > number){
      print('higher then true');
      print(computerGuess);}
      if(computerGuess > number ) {
        print(' computer guessed higher then true');
      }
        if(userGuess == number){
        print('you won');
        }
      if(computerGuess == number){
        print('computer won');
          }
  }
}
main(){
  guessWithPC guess = guessWithPC();
  guess.run();
}
EN

回答 1

Stack Overflow用户

发布于 2022-04-25 17:16:37

您需要在变量int.parse中保存userGuess的值。

代码语言:javascript
复制
 userGuess = stdin.readLineSync();
 userGuess=int.parse(userGuess);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72001675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档