ファイルから学生の記録を取得し、それらを配列に入れるために、このプログラムを作成しました。次に、それらをバブルソートして印刷しようとします。
import java.io.*;
import java.util.Scanner;
public class StudentTest
{
public static void main(String[] args)
{
String name;
String address;
String major;
double gpa;
int classLevel;
int college;
String idNumber;
Scanner fileIn = null;
try
{
fileIn = new Scanner (new FileInputStream("student.dat"));
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
System.exit(0);
}
Student[] aStudent = new Student[15];
int index = 0;
for (index=0; index < 15;)
{
while (fileIn.hasNext())
{
name = fileIn.nextLine();
address = fileIn.nextLine();
major = fileIn.nextLine();
gpa = fileIn.nextDouble();
classLevel = fileIn.nextInt();
college = fileIn.nextInt();
fileIn.nextLine();
idNumber = fileIn.nextLine();
aStudent[index] = new Student(name, address, major, gpa, classLevel, college, idNumber);
aStudent[index].Display();
System.out.println(index);
index++;
}
}
Student temp= null;
for (int pass = 0; pass < (index-1); pass++)
{
for (int c = 0; c < (index - 1); c++)
{
if (aStudent[c].getName().compareTo(aStudent[c+1].getName()) > 0)
{
temp = aStudent[c];
aStudent[c]=aStudent[+1];
aStudent[+1]=temp;
}
}
}
for (int d = 0; d < aStudent.length; d++)
{
aStudent[d].Display();
System.out.println();
//aStudent[d].Display();
}
//System.out.println(aStudent);
}
}
コンソールは、配列をロードしているときにソートされていないリストの最初の出力を表示し、そこに座っています。私はそれを10分間放置しましたが、まだEclipseに赤い「終了」アイコンが表示されていました(まだ実行中であることを示しています)。また、ずっと私のリソースの半分を食べていました。どうすればこれを解決できますか?
ありがとう