未处理的异常: 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完成的处理
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();
}发布于 2022-04-25 17:16:37
您需要在变量int.parse中保存userGuess的值。
userGuess = stdin.readLineSync();
userGuess=int.parse(userGuess);https://stackoverflow.com/questions/72001675
复制相似问题