你的代碼不會編譯。它遭受很多問題(包括語法問題)。
您有語法錯誤 - 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