有人可以解释我是如何得到这个答案的:
三次两次= 6次
码:
public class Params1 {
public static void main(String[] args) {
String one = "two";
String two = "three";
String three = "1";
int number = 20;
sentence(one, two, 3);
}
public static void sentence(String three, String one, int number) {
String str1 = one + " times " + three + " = " + (number * 2);
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个有用的图表:

我希望它很清楚.
以下是如何使相同的代码更容易混淆:
public static void main(String[] args) {
String a = "three";
String b = "two";
sentence(a, b, 3);
}
public static void sentence(String a, String b, int number) {
String str1 = a + " times " + b + " = " + (number * 2);
System.out.println(str1); // to let you inspect the value
}
Run Code Online (Sandbox Code Playgroud)
在打电话给 sentence()
sentence(one, two, 3);
Run Code Online (Sandbox Code Playgroud)
为了论证,只需用它们的值替换所有变量:
sentence( "two", "three", 3);
Run Code Online (Sandbox Code Playgroud)
然后看一下该函数内部参数的值是什么:
three == "two"
one == "three"
number == 3
Run Code Online (Sandbox Code Playgroud)
然后替换你生成的句子中的参数,你就得到了结果!
此外,你的变量名称并不是真的不言自明.你应该重新考虑它们以防止这种误解.
| 归档时间: |
|
| 查看次数: |
149 次 |
| 最近记录: |