1.从键盘上输入10个整数的数列,将10个数按从小到大顺序排列,输出原数列和排序后的数列。
/*
* 题目描述
1.从键盘上输入10个整数的数列,将10个数按从小到大顺序排列,输出原数列和排序后的数列。
输入描述
输入10个整数,用空格分隔。
输出描述
分为二行,第一行为原数列,第二行为排序结果,提示汉字与数列之间用冒号隔开。
输入样例
24 32 12 15 17 56 33 25 28 11
输出样例
原数列:24 32 12 15 17 56 33 25 28 11
排序结果:11 12 15 17 24 25 28 32 33 56
*/
package exam1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
* @author Administrator
*/
public class test1 {
??? List<String> date = new ArrayList();
??? List<String> sortDate = new ArrayList();
??? public List<String> getSortDate() {
??????? return sortDate;
??? }
??? public void setSortDate(List<String> sortDate) {
???????? Collections.sort(date);
??????? this.sortDate = sortDate;
??? }
??? public List<String> getDate() {
??????? return date;
??? }
??? public void setDate(int n) throws IOException {
??????? List list = new ArrayList();
??????? BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
??????? String inputString = br.readLine();
??????? String [] nums=inputString.split(" ");
??????? for(int i=0;i<nums.length;i++){
??????? list.add(Integer.parseInt(nums[i]));
??????? }
??????? this.date = list;
??? }
??? public void print(List date){
??????? for(int i=0;i<date.size();i++)
??????? System.out.print(date.get(i)+" ");
??? }
??? public static void main(String [] args) throws IOException{
??????? test1? test = new test1();
??????? test.setDate(10);
??????? System.out.print("原数列:");
??????? test.print(test.getDate());
??????? test.setSortDate(test.getDate());
??????? System.out.print("\n排序数列:");
??????? test.print(test.getSortDate());
??? }
}
?