\ tが常に正しい間隔を提供するとは限らないため、プログラムによって保存された学生に関する情報を表形式で出力しようとしています。そうするために、私はこの質問に出くわし、同様の解決策を有効にしようとしました。ただし、コードをそのように実行しようとすると、コードのフォーマット行でエラーが発生します。
public void displayStudents (){
System.out.println ("\n-----------------------------");
System.out.println ("Email System - Display Students");
System.out.println ("-----------------------------");
System.out.format("%10s%15d%15s%15s%20s", "Grade", "Last Name", "First Name", "Student Number", "Parent Email");
StudentNode current = top;
while (current != null){
Student read = current.getStudentNode();
System.out.format ("%10s%15d%15s%15s%20s", ""+read.getClass(), read.getLastName(), read.getFirstName(), ""+read.getStudentNum(), read.getParentEmail());
//This will output with a set number of character spaces per field, giving the list a table-like quality
}
}//End of displayStudents
コードの目的は、次の画像のような方法で出力することです。
エラーを見つけるのを手伝ってください。これを実行する別の方法はおそらくありますか?
ありがとう。
編集:私が得ているエラーは
GradeException in thread "main" java.util.IllegalFormatConversionException: d != java.lang.String
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at StudentList.displayStudents(StudentList.java:184)
at OnlineCommunications.emailOption(OnlineCommunications.java:403)
at OnlineCommunications.main(OnlineCommunications.java:451)
Gradeは整数で、Longはdoubleであることに注意してください。