- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我声明 flag false 时,为什么 while 循环继续循环?一旦我输入正确的输入,程序就应该结束。任何帮助将不胜感激。刚接触java。非常感谢大家!
import javax.swing.JOptionPane;
import java.util.*;
public class Project1Chang
{
public static void main(String[] args)
{
String name;
String sex;
int height;
boolean flag = true;
JOptionPane.showMessageDialog (null, "This program calculates tidal volume.", "Tidal Volume Calculator", JOptionPane.INFORMATION_MESSAGE);
name = JOptionPane.showInputDialog("What is your name?");
sex = JOptionPane.showInputDialog("What is your sex?");
while (flag = true)
{
height = Integer.parseInt (JOptionPane.showInputDialog("What is your height? (48-84 inches or 114-213 centimeters) \nEnter whole numbers only."));
if (height <= 84 && height >= 48)
{
if (sex.equalsIgnoreCase("male") || sex.equalsIgnoreCase("m"))
{
double malePbwInch = 50 + 2.3 * (height - 60);
JOptionPane.showMessageDialog(null, malePbwInch);
flag = false;
}
}
else if (height <= 213 && height >= 114)
{
if (sex.equalsIgnoreCase("male") || sex.equalsIgnoreCase("m"))
{
double malePbwCm = 50 + .91 * (height - 152.4);
JOptionPane.showMessageDialog(null, malePbwCm);
flag = false;
}
}
else
{
JOptionPane.showMessageDialog(null, "This is an invalid input. Try again.");
}
}
}
}
最佳答案
即使是经验丰富的程序员也会时不时地犯这样的错误:您将 true 分配给 flag,因此条件始终为 true。您需要双等于比较运算符
while (flag == true)
或者只是
while (flag)
关于java - 为什么while循环一直循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32803365/
我有一个在 Android 市场上相当流行的应用程序,它允许数以万计的用户按下一个按钮并向它发出语音命令。然后我就可以做很多不同的事情,比如给他们提供当前的天气预报等等...... 无论如何,我的应用
令人惊讶的是,标题基本上解释了它。我们有一个我们的客户制作的页面,我们正在重新创建该页面。 页面高度会一直增加,直到(我假设是这样)浏览器达到它的极限。我已经尝试过 Firebug 和 W3 验证器,
我是 react-native 的新手,试图创建我自己的组件,但它一直显示一个空屏幕。 这是我的组件代码 class BoxComponent extends Component { cons
我正在为我的 PHP 元素创建一个非常简单的博客,但遇到了一个简单的问题。我无法让我的页眉图像一直 float 。我有一个横幅,左边有一些文字,我有一个 1px 的切片,在可以选择的任何分辨率的宽度上
为什么我可以在另一个 Controller 的 View 中访问一个 Controller 的辅助方法?有没有办法在不破解/修补 Rails 的情况下禁用它? 最佳答案 @George Schreib
我正在使用带有最新 ADT 插件的 Eclipse Kepler SP2。每隔一分钟 Eclipse 就会说“为 Android 4.4.2 加载数据”并阻止我想做的一切。我在不同的文件夹中有几个 E
我是一名优秀的程序员,十分优秀!