import java.util.Scanner;
public class J252 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("テストの受験者数を入力して下さい");
int viQuantity = scan.nextInt();
int[] a1iStore = new int[viQuantity];
for (int i = 0; i < a1iStore.length; i++) {
System.out.println((i + 1) + "番目の点数を入力してください");
a1iStore[i] = scan.nextInt();
}
System.out.println("昇順:1 降順:2");
int viDirection = scan.nextInt();
// Collections.sort(cal1Index, (i1, i2) -> a1iKyoukaSum[i2]-a1iKyoukaSum[i1]);
// バブルソート:下記サイトのコードを修正しています
// https://techacademy.jp/magazine/19444
for (int i = 0; i < a1iStore.length - 1; i++) {
for (int j = a1iStore.length - 1; j > i; j--) {
int j0, jm1, cmp;
j0 = a1iStore[j];
jm1 = a1iStore[j - 1];
cmp = jm1-j0;
if (viDirection == 2) {
cmp = -cmp;
}
if (0<cmp) {
a1iStore[j - 1] = j0;
a1iStore[j] = jm1;
}
}
}
if (viDirection != 2) {
System.out.println("** 得点順(昇順) **");
} else {
System.out.println("** 得点順(降順) **");
}
for (int i = 0; i < a1iStore.length; i++) {
System.out.println(a1iStore[i]+"点");
}
}
}
|
|