package txx;
public class Tr {
static void func(int a, String b, String c) {
a = 1;
b.trim(); //这个是正确的(验证代码:
String b1 = b.trim();
System.out.println(b1);
输出的是Hello World)
c = b;
}
public static void main(String[] args) {
int a = 0;
String b = " Hello World ";
String c = " OK ";
func(a, b, c);
System.out.println("" + a + "," + b + "," + c);
}
}
原因是:
在程序入口你是调用了func()方法。但你是在主函数里输出的,肯定还是初始化的值了懂吗?
注意:你传进去的参数要在方法里用...
还有你在func里的 b.trim();并没有给b赋值...
b肯定还是初始化的值了..
你应该用b来接受b.trim();
class Tr{
static void func(int a, String b, String c) {
a = 1;
b=b.trim();
c = b;
System.out.println("" + a + "," + b + "," + c);
}
}这样输出的结果就是
1,Hello World,Hello World
|