C++,python,热爱算法和机器学习
全部博文(1214)
分类: Java
2015-06-26 10:42:23
1
2
3
4
5
6
7
8
9
10
11
|
public class Test1 {
public static void main(String[] args) {
int n = 3 ;
System.out.println( "Before change, n = " + n);
changeData(n);
System.out.println( "After changeData(n), n = " + n);
}
public static void changeData( int nn) {
n = 10 ;
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
public class Test2 {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer( "Hello " );
System.out.println( "Before change, sb = " + sb);
changeData(sb);
System.out.println( "After changeData(n), sb = " + sb);
}
public static void changeData(StringBuffer strBuf) {
strBuf.append( "World!" );
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public class Test3 {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer( "Hello " );
System.out.println( "Before change, sb = " + sb);
changeData(sb);
System.out.println( "After changeData(n), sb = " + sb);
}
public static void changeData(StringBuffer strBuf) {
strBuf = new StringBuffer( "Hi " );
strBuf.append( "World!" );
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public class Test4 {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer( "Hello " );
System.out.println( "Before change, sb = " + sb);
changeData(sb);
System.out.println( "After changeData(n), sb = " + sb);
}
public static void changeData(StringBuffer strBuf) {
StringBuffer sb2 = new StringBuffer( "Hi " );
strBuf = sb2;
sb2.append( "World!" );
}
}
|