/** * 题目名称奇数单增序列 p * 题目来源http://noi.openjudge.cn/ch0110/02/ p * 程序功能按升序输出指定整数序列中的奇数 * * author 潘磊just_panleijust.edu.cn * version 1.0 */importjava.util.List;importjava.util.ArrayList;importjava.util.Collections;importjava.util.Scanner;publicclassMain{/** * 返回指定整数序列中的奇数序列。 * * param list 指定整数序列。 * return list中的奇数序列。 */publicListIntegeroddElements(ListIntegerlist){ListIntegeroddsnewArrayList();// list中的奇数序列/* 依次遍历list中的所有元素 */for(inte:list){if(e%21){// 如果当前元素是奇数odds.add(e);// 将其推入odds中}}returnodds;}publicstaticvoidmain(String[]args){MaincallnewMain();ScannerinputnewScanner(System.in);intNinput.nextInt();ListIntegerlistnewArrayList();for(inti0;iN;i){list.add(input.nextInt());}ListIntegeroddscall.oddElements(list);Collections.sort(odds);// 调用Collections的sort方法对odds序列进行升序排序System.out.print(odds.get(0));for(inti1;iodds.size();i){System.out.print(,odds.get(i));}}}