本帖最后由 xiong910627 于 2014-9-5 12:22 编辑
编写一个函数,函数内输出一个字符串,并在主函数内调用它。
public class Test2 {
//定义构造函数
public static void demo(String str)
{
// 输出一个字符串
str = "赋值调用!";
System.out.println(str);
}
public static final void main(String[] args)
{
// 在主函数中调用
String str = "Hello World!";
demo(str);
System.out.println(str);
}
}
|
|