java - 使用在 if 语句中更改的变量
问题描述
我正在用 JAVA 编写一个程序,我需要更改一个布尔值,但我无法修复它。
布置如下
while(statement){
Boolean behind = true;
if (behind == true){
do something
behind = false;
}
if (behind == false){
do something else
behind = true;
}
}
所以基本上我的程序需要迭代“做某事”和“做其他事情”。但我认为我的布尔值behind
不会被 if 语句改变,因为那个“版本”behind
只存在于语句中。有关如何应对此问题的任何建议?
解决方案
Boolean behind = true;
while(statement){
if (behind){
do something;
behind = false;
}else{
do something else;
behind = true;
}
}
推荐阅读
- android - 如何以编程方式接受 Android Studio 的 WebView 上的 cookie?
- r - 热图错误:“x”必须是数字矩阵
- node.js - 将 Nodejs JSON 对象转换为 List
- google-sheets - 如何取消隐藏从操作栏中消失的图标?
- postgresql - 从存储过程调用 scala 函数
- python - 在大熊猫数据框中替换大于 1 的值
- http-redirect - 如何在打开重定向的情况下在 Postman 测试中检索最终 URL
- python - How can I split a text from a parenthesis in a CSV, and create another column with it
- regex - 将 Unicode 字符与正则表达式匹配
- javascript - 标签为空时如何隐藏?