0 java string if-statement boolean
为什么这会回归真实?
String b = "(5, 5)";
String a = "(7, 8)" ;
if(a.equals(b));
{
System.out.printf("Somehow \"%s\" and \"%s\" are the same" ,a,b);
}
Run Code Online (Sandbox Code Playgroud)
输出:
Somehow "(7, 8)" and "(5, 5)" are the same
Run Code Online (Sandbox Code Playgroud)
您的代码相当于:
if(a.equals(b)) { }
{
System.out.printf("Somehow \"%s\" and \"%s\" are the same" ,a,b);
}
Run Code Online (Sandbox Code Playgroud)
因此,块中的print语句将始终执行,而不管条件如何,因为该主体if不包含该语句.
空语句什么都不做.
EmptyStatement:
Run Code Online (Sandbox Code Playgroud);执行空语句总是正常完成
| 归档时间: |
|
| 查看次数: |
69 次 |
| 最近记录: |