我需要使用一個靜態方法,它從另一個字符串數組中返回一個字符串數組。因此,如果形式參數中的數組等於「你好」,那麼「返回」需要是「olleh」,「ereht」。反向字符串數組w /方法
我的想法是使用charAt命令,但它似乎不適用於數組。我無法使用內置方法一步解決此問題。我也不知道如何移動到數組中的下一個元素。這是我的代碼。
部分主要方法,設置了原始數組:
String [] d = {"hey","hello"};
System.out.println(Arrays.toString(count(d)));
我的方法:
private static String [] count(String[] d)
{
String[] reverse = new String [d.length];
int l = d.length;
for(int i = l -1; i >= 0; i--)
{
reverse = reverse + d.charAt(i);
}
return reverse;
}
這顯示了他們的方式爲一個Int數組的一部分。我不知道如何爲字符串數組做這件事。 – frillybob
試試這個... http://stackoverflow.com/a/22282907/3660930 – Ash