这是代码,
public class Solution {
public static void main(String[] args) {
compare(5);
}
public static void compare(int a) {
if(a==5)
System.out.println("The number is equal to 5");
if(a<5)
System.out.println("The number is less than 5");
else
System.out.println("The number is greater than 5");
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出,
The number is equal to 5
The number is greater than 5
Run Code Online (Sandbox Code Playgroud)
我刚刚调用了compare方法一次,为什么它执行两次?