/** * 降序升序 * * @param str * @since 0.0.1 */ public void sort(String str){ String[] nums = str.split(" "); List<Integer> odd = new ArrayList<Integer>(); List<Integer> even = new ArrayList<Integer>(); for (String string : nums) { Integer temp = Integer.valueOf(string); if (temp%2==0) { even.add(temp); }else{ odd.add(temp); } } System.out.println("结果:"); Collections.sort(odd); for (int i = odd.size()-1; i >=0; i--) { System.out.print(odd.get(i)+"\t"); } Collections.sort(even); System.out.println(); for (Integer integer : even) { System.out.print(integer+"\t"); } }
时间: 2024-12-06 03:06:34