【发布时间】:2016-11-13 13:24:45
【问题描述】:
我已经对 Engduino 进行了编程,以使用它的热敏电阻测量房间内的温度并将值输出到串行端口;程序开始时输出“start temp”,程序结束时输出“end temp”,其间每2秒输出一次温度值。我在处理中使用 .readString 来读取这些值,因为它们正在被测量。
String str = myEngduino.readString();
if(str!=null){
println(str);
}
这段代码工作正常,打印到控制台的值确实是“开始温度”,然后是读取温度,然后是程序完成时的“结束温度”。所以我不明白为什么这段代码中的 if 语句永远不会计算为 true:
String str = myEngduino.readString();
if(str!=null){
println(str);
if(str.equals("start temp")){
println("START");
}
}
str 肯定设置为“start temp”,因为它被打印到控制台,那么为什么我的 if 语句此时不会评估为 true?
【问题讨论】:
标签: string if-statement processing equals