import java.io.*;public class Sort { public static void main(String args[]) { int Array[] = new int[10]; //Define new array for the number
int temp;
int i = 0;
int count = 9; //counter
int j;
String sort_str="";
String change; //The string for store input numbers System.out.println ("Please Enter The Number:");//Print hint while(i<10) { //Get input numbers and store in array,ten for max
try{
BufferedReader br =
new BufferedReader (new InputStreamReader(System.in));
change = br.readLine();
Array[i] = Integer.parseInt(change); //Change the string into Int
}catch(IOException e) {}; //Get one number and store in array
i++; //Counter add 1 for input
} for(i = 0;i < 10;i++) { //Sort the numbers
for(j = 0;j < count;j++) {
if(Array[j] < Array[j+1]) { //Compare,the bigger inhead
temp = Array[j];
Array[j] = Array[j+1];
Array[j+1] = temp;
}
}
count--; //Counter for sort
} System.out.println ("The Sorted Number Are:");
//File filename = new File("c:\\","wjm000.txt");
try{
FileWriter myFileoutputstream= new FileWriter("c:\\wjmmml.txt",true); for(i = 0;i < 10;i++) { //Print the sorted numbers in screen
System.out.print (" "+Array[i]);
sort_str =sort_str+" "+ Array[i];
}
myFileoutputstream.write(sort_str);
myFileoutputstream.close();
}catch(Exception e){
System.out.println("ioException");
}
}}
结果将输出到c;盘下的wjmmml.txt文件中。
int temp;
int i = 0;
int count = 9; //counter
int j;
String sort_str="";
String change; //The string for store input numbers System.out.println ("Please Enter The Number:");//Print hint while(i<10) { //Get input numbers and store in array,ten for max
try{
BufferedReader br =
new BufferedReader (new InputStreamReader(System.in));
change = br.readLine();
Array[i] = Integer.parseInt(change); //Change the string into Int
}catch(IOException e) {}; //Get one number and store in array
i++; //Counter add 1 for input
} for(i = 0;i < 10;i++) { //Sort the numbers
for(j = 0;j < count;j++) {
if(Array[j] < Array[j+1]) { //Compare,the bigger inhead
temp = Array[j];
Array[j] = Array[j+1];
Array[j+1] = temp;
}
}
count--; //Counter for sort
} System.out.println ("The Sorted Number Are:");
//File filename = new File("c:\\","wjm000.txt");
try{
FileWriter myFileoutputstream= new FileWriter("c:\\wjmmml.txt",true); for(i = 0;i < 10;i++) { //Print the sorted numbers in screen
System.out.print (" "+Array[i]);
sort_str =sort_str+" "+ Array[i];
}
myFileoutputstream.write(sort_str);
myFileoutputstream.close();
}catch(Exception e){
System.out.println("ioException");
}
}}
结果将输出到c;盘下的wjmmml.txt文件中。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货