星期三, 12月 28, 2005

Lab 12-19-2005 Sorting

import java.io.*;

public class untitled {
public untitled() {
}

public static void main(String[] args) throws IOException {
double[] score = new double[5];
int index, a, b;
double x;
BufferedReader keyboard = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("Enter 5 numbers :");
for (index = 0; index < 5; index++) {
score[index] = Double.parseDouble(keyboard.readLine());
}
System.out.println("and the new score =");
for (a = 0; a < 5;a++) {
for(b=a+1;b<5;b++){
if (score[a] > score[b]) {
x = score[a];
score[a] = score[b];
score[b] = x;
}
}
}
for (index = 0; index < 5; index++) {
System.out.println(score[index]);
}
}
}

0 Comments:

張貼留言

<< Home