日期:2014-05-20 浏览次数:20649 次
package test; public class Test1 { static String[] ls={"A","B","C","V","G","H","K"}; static String[] ses={"B","G","K"}; /** * @param args */ public static void main(String[] args) { int indexSes = 0; int indexLs = 0; while (indexSes <= ses.length - 1) { while (true) { int indexTemp = search(ses[indexSes], indexLs); if (indexTemp != -1 && indexTemp != indexLs) { String tempS = ls[indexLs]; ls[indexLs] = ls[indexTemp]; ls[indexTemp] = tempS; } if (indexTemp != -1) indexLs++; else break; } indexSes++; } for (String string : ls) { System.out.print(string + " "); } } private static int search(String c, int startIndex) { for (int i = startIndex; i <= ls.length - 1; i++) { if (ls[i].equals(c)) return i; } return -1; } }
------解决方案--------------------