【发布时间】:2015-05-26 19:42:20
【问题描述】:
我正在尝试解决使用布尔表达式的练习问题。我想创建一个程序来说明是否有人应该骑自行车。我有两个变量,想写一个 AND 语句和一个 OR 语句。我的两个变量是路况和温度。
编辑:在我收到的帮助下,我取得了一些进展。我在下面的第 22 行遇到了另一个问题;
// Program to decide if biking or driving to work is best
import javax.swing.*;
public class SNHU3_4Paper {
public static void main(String[] args) {
String temperature;
String roadCondition;
double temp;
double weather = 50;
double road;
boolean roadIsdry = true;
temperature = JOptionPane.showInputDialog("Enter temperature outside: ");
roadCondition = JOptionPane.showInputDialog("Is the road dry (true or false): ");
temp = Double.parseDouble(temperature);
road = Double.parseDouble(roadCondition);
if (temp >= weather && road == roadIsdry)
JOptionPane.showMessageDialog(null, "Bike to work");
else {
JOptionPane.showMessageDialog(null, "Drive to work");
}
}
}
【问题讨论】:
-
当您使用布尔值时,没有 0 或 1。只有真或假。
-
如果您发布当前代码并准确解释您要执行的操作,将会很有帮助。