Lab 12-19-2005 Sorting
package untitled14;
import java.io.*;
public class add {
private static Object keyboard;
public static void main(String[] args) throws IOException,
NumberFormatException {
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.
in));
double tem;
double[] number = new double[5];
System.out.println("輸入5個數:");
for (int i = 0; i < 5; i++) {
number[i] = Double.parseDouble(keyboard.readLine());
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (number[i] < number[j]) {
tem = number[i];
number[i] = number[j];
number[j] = tem;
}
}
}
System.out.println();
System.out.println("結果");
for (int i = 0; i < 5; i++){
System.out.println(number[i]);
}
}
}
import java.io.*;
public class add {
private static Object keyboard;
public static void main(String[] args) throws IOException,
NumberFormatException {
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.
in));
double tem;
double[] number = new double[5];
System.out.println("輸入5個數:");
for (int i = 0; i < 5; i++) {
number[i] = Double.parseDouble(keyboard.readLine());
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (number[i] < number[j]) {
tem = number[i];
number[i] = number[j];
number[j] = tem;
}
}
}
System.out.println();
System.out.println("結果");
for (int i = 0; i < 5; i++){
System.out.println(number[i]);
}
}
}
0 Comments:
張貼留言
<< Home