你的代码不会编译。它遭受很多问题(包括语法问题)。
您有语法错误 - retrun
应该是return
。
demo
后,你应该有括号(空,如果你不需要参数)
另外,String[] xs = new String {"a","b","c","d"};
应该是:
String[] xs = new String[] {"a","b","c","d"};
您的代码应该是这个样子:
public String[] demo() //Added()
{
String[] xs = new String[] {"a","b","c","d"}; //added []
String[] ret = new String[4];
ret[0]=xs[0];
ret[1]=xs[1];
ret[2]=xs[2];
ret[3]=xs[3];
return ret;
}
放在一起:
public static void main(String args[])
{
String[] res = demo();
for(String str : res)
System.out.println(str); //Will print the strings in the array that
} //was returned from the method demo()
public static String[] demo() //for the sake of example, I made it static.
{
String[] xs = new String[] {"a","b","c","d"};
String[] ret = new String[4];
ret[0]=xs[0];
ret[1]=xs[1];
ret[2]=xs[2];
ret[3]=xs[3];
return ret;
}
,你能告诉我们你是如何在你的主要尝试打印? – duffy356 2013-03-12 11:41:23
“*因为我试过了,它力度不够*”=>什么都不起作用?你*从这个方法返回一个数组。 – assylias 2013-03-12 11:41:30
我已经低估了你,因为你没有任何证据证明你有过预研究。 *你*尝试过什么? – 2013-03-12 11:41:44