【发布时间】:2022-01-08 07:37:16
【问题描述】:
import "dart:io";
import "dart:math";
String promptStudent(){
print("are you a student?");
String Student = stdin.readLineSync()!;
return Student;
}
String promptSmart(){
print("2+2=?");
String Smart = stdin.readLineSync()!;
return Smart;
}
void main() {
String student = promptStudent();
if(student == "yes"){
bool isStudent = true;
} else() {
bool isStudent = false;
};
String smart = promptSmart();
if(smart == "4"){
bool isSmart = true;
} else() {
bool isSmart = false;
};
if(isSmart && isStudent) {
print("he is a smart student");
}
else if(isSmart && !isStudent) {
print("he is smart but not a student");
}
else if(!isSmart && isStudent) {
print("he isnt smart but a student");
}
else if(!isSmart && !isStudent) {
print("he is not smart and not a student");
};
}
我想通过用户输入设置一个布尔值(如果 2+2 的答案是 4 他很聪明等),但我遇到了以下问题:
main.dart:42:24:错误:找不到吸气剂:'isStudent'。别的 if(!isSmart && !isStudent) {
这里有什么问题?我该如何解决?
【问题讨论】:
标签: dart if-statement boolean