我是Java學習者並測試Java代碼,目前在Java中並沒有太多掌握。以表格形式顯示兩個一維和一個二維數組
目前我想實現的是我有兩個一維數組的String和一個整數的二維數組。我希望結果以表格形式顯示,但我無法這樣做。我的代碼如下。
import java.util.*;
public class StudentResults {
static String studentName;
static String courseName;
static int courseMarks;
static String[] student = { "Jack Smith", "Jim Lucas", "Beck Barber",
"Ann Walker", "Lucy Boxer" };
static String[] course = { "Maths", "Business", "Java", "Design", "Project" };
public static void studentMarks() {
int[][] marks = { { 89, 70, 56, 87, 65 }, { 70, 65, 70, 83, 78 },
{ 60, 90, 63, 56, 79 }, { 74, 78, 45, 73, 85 },
{ 80, 90, 60, 70, 80 } };
for (int i = 0; i < student.length; i++) {
studentName = student[i];
System.out.printf("\t\t" + studentName + "\t");
}
System.out.println("");
for (int j = 0; j < course.length; j++) {
courseName = course[j];
System.out.println(courseName + "\t");
}
for (int m = 0; m < marks.length; m++) {
for (int n = 0; n < marks.length; n++) {
courseMarks = marks[m][n];
System.out.print("\t\t" + courseMarks + "\t\t");
}
System.out.println("");
}
}
public static void main(String args[]) {
studentMarks();
}
}
我得到的標記輸出是在表中,但不與課程名稱內聯。只是想知道我是否有辦法以我的工作方式實現這一目標。
乾杯,
是System.out.print使用(courseName + 「\ t」 的); – Mohit 2014-10-30 09:47:28