【发布时间】:2017-04-06 05:38:32
【问题描述】:
好吧,假设我有一个由 4 个整数组成的数组 ==
int[] input = new int[]{1,2,3,4};
//now I some how converted these numbers into words and gets an array:-
String Str = new String[]{one,two,three,four};
//then I run a sort method on Str.
Arrays.sort(Str);
//and I got this array in the end ::: {four,one,three,two}
现在我想将其重新转换为数字(int),这样我的最终结果应该如下所示:- {4,1,3,2}
在夏天:- 我想通过它的英文(单词)表示对输入的 int 数组进行排序
示例:-
[input] [convert to words] [sorting] [Result]
{1,2,3,4} => {一,二,三,四} =>{四,一,三,二} => 4,1,3,2
{55,23,3,45} =>{五十五、二十三、三、四十五} => {五十五、四十五、三、二十三} => {55,45,3,23 }
所以,到目前为止,我设法将输入转换为单词并对其进行排序,但我不知道如何将 Str array 转换回其原始 int 数组,如上面的示例所示...
真正的问题:- 我知道我可以使用循环和 数组..但我想知道是否可以使用数组交换来做到这一点??[也许 通过它的索引??]
P.s:- 很抱歉我可能给您带来任何方便。并提前感谢
【问题讨论】:
-
有一些假设,是的,这是可能的。您可能应该从实现自己的排序开始,然后当您交换 word 数组中的元素时 - 也交换您的 number 数组中的元素。
标签: java arrays numbers swap words