我試圖以表格式格式輸出關於我的程序存儲的學生的信息,因爲\ t並不總是提供正確的間距。爲了做到這一點,我遇到了this question,並試圖啓用類似的解決方案。但是,當我試圖執行它時,我正在獲取代碼中格式行的錯誤。像表格格式化Java輸出
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
該代碼的目標是以類似於以下圖像的方式輸出。
請幫助我找到我的錯誤。有沒有其他方法可以執行此操作?
謝謝。
編輯:錯誤(S)我得到的
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)
應當注意的是,等級是一個整數,龍是雙。
你有什麼樣的問題? – 2013-02-24 13:36:56
對不起,我添加了錯誤。@LuiggiMendoza – n0shadow 2013-02-24 13:40:34