我需要使用一个静态方法,它从另一个字符串数组中返回一个字符串数组。因此,如果形式参数中的数组等于“你好”,那么“返回”需要是“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