请教一个Java程序问题(悬赏500聚元)
RT。问题对于高手来说小菜一碟,可是对菜鸟来说就是一筹莫展。就是把两个if条件句下的两个数组分别排序,再输出排好后的序号。
求高手帮忙,不胜感激,程序可行的话马上转500聚元,略表心意吧 没理解你要做什么 稍微举个例子 import java.util.Arrays;
public class ArraySortierenClass {
public static void main(String[] args) {
String[] s = new String;
s = "Paul";
s = "Willi";
s = "Anton";
s = "Karl";
s = "Sepp";
s = "Petra";
s = "Peter";
Arrays.sort(s);
for (int n = 0; n < s.length; n++) {
System.out.println(s);
}
}
} 比如 a[]={2,9,8,6};b[]={3,7,8}
对a升序排列,然后输出相应的序号:1,4,3,2
对b降序排列,然后输出相应的序号:3,2,1
多谢! 本帖最后由 leelight 于 2015-4-19 11:40 编辑
public class ArrayIndexComparator implements Comparator<Integer>
{
private final int[] array;
public ArrayIndexComparator(int[] array)
{
this.array = array;
}
public Integer[] createIndexArray()
{
Integer[] indexes = new Integer;
for (int i = 0; i < array.length; i++)
{
indexes = i;
}
return indexes;
}
@Override
public int compare(Integer index1, Integer index2)
{
return array>array;
}
}
public class ArrayIndexComparatorDesc implements Comparator<Integer>
{
private final int[] array;
public ArrayIndexComparator(int[] array)
{
this.array = array;
}
public Integer[] createIndexArray()
{
Integer[] indexes = new Integer;
for (int i = 0; i < array.length; i++)
{
indexes = i; // Autoboxing
}
return indexes;
}
@Override
public int compare(Integer index1, Integer index2)
{
return array>array;
}
}
升序:
int[] countries = { 5, 2,3, 8, 19};
ArrayIndexComparator comparator = new ArrayIndexComparator(countries);
Integer[] indexes = comparator.createIndexArray();
Arrays.sort(indexes, comparator);
for (int n = 0; n < indexes.length; n++) {
System.out.println(indexes);
}
降序:
int[] countries = { 5, 2,3, 8, 19};
ArrayIndexComparator comparator = new ArrayIndexComparatorDesc(countries);
Integer[] indexes = comparator.createIndexArray();
Arrays.sort(indexes, comparator);
for (int n = 0; n < indexes.length; n++) {
System.out.println(indexes);
}
未经实际运行测试,不承担任何可能导致的不良后果 leelight 发表于 2015-4-19 01:01
升序:升序:未经实际运行测试,不承担任何可能导致的不良后果
哇塞,您这一看就是专业级别的,偶先花时间研究研究,非常非常感谢 weste. 发表于 2015-4-19 11:06
哇塞,您这一看就是专业级别的,偶先花时间研究研究,非常非常感谢
lz亏欠IT民工血汗500聚元,带着小姨子跑了...........{:4_292:} leelight 发表于 2015-4-19 11:44
lz亏欠IT民工血汗500聚元,带着小姨子跑了...........
唉呀,不好意思不好意思,我这程序还没研究明白呢。马上转
页:
[1]