2016-05-05 190 views
1
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: '<'

回答

1

你從stdin.readLineSync()的字符串。您需要將其轉換爲數字以便能夠將其與另一個數字進行比較

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