转载自:http://blog.youkuaiyun.com/fenglibing/article/details/1753536
1.参数传递
public class T {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "abcd";
int i = 10;
change(str, i);
System.out.println(str);
System.out.println(i);
}
private static void change(String str, int i) {
// TODO Auto-generated method stub
str = "welcome";
i = 20;
}
}
输出:abcd 10
2.for循环的执行顺序:
public class T2 {
static boolean foo(char c) {
System.out.print(c);
return true;
}
public static void main(String[] argv) {
int i = 0;
for (foo('A'); foo('B') && (i < 2); foo('C')) {
i++;
foo('D');
}
}
}
What is the result?
A. ABDCBDCB
B. ABCDABCD
C. Compilation fails.
D. An exception is thrown at runtime.
//
输出结果是:
ABDCBDCB
本文通过两个Java示例程序详细介绍了Java中参数传递的特点以及for循环的执行顺序。首先,通过一个简单的例子展示了基本类型和引用类型的参数传递区别;其次,通过另一个复杂的for循环结构说明了循环中条件判断和更新表达式的执行顺序。

被折叠的 条评论
为什么被折叠?



