public class Demo {
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
int[] arr = new int[5];
for (int i = 0; i < 5; i++) {
System.out.println("请输入第"+i+"个整数");
arr[i] = s.nextInt();
System.out.println(arr[i]);
}
for (int i = 0; i < arr.length - 1; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[j] > arr[i]) {
int temp;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
ArrayList<Integer> list = new ArrayList<Integer>();
for (int j = 0; j < arr.length; j++) {
list.add(arr[j]);
}
System.out.println(list);
FileOutputStream fos = new FileOutputStream(new File("a.txt"));
byte []b=new byte[1024];
for (int i = 0; i <list.size(); i++) {
fos.write(list.get(i));
}
fos.close();
}
} |