コードはコンパイルされません。それは多くの問題(構文の問題を含む)に悩まされています。
構文エラーがあります-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;
}