【发布时间】:2019-06-20 21:55:25
【问题描述】:
我正在尝试为成绩报告制作一个表格,该表格应包含 5 列,分别是班级、描述、单位、成绩和成绩点。 但是,我无法使输出相互对齐。 我只是简单地使用“\t”。 有没有办法在 Java 中将输出制作为表格?
import java.util.*;
public class Project1_Trial2 {
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
//Input the term
System.out.println("Please enter the term of your grade calculation (for example, Fall 2015): ");
String term = scanner.nextLine();
//Input the number of courses that the student is enrolled in
System.out.println("Please enter the number of courses that you are enrolled in "+term+": ");
int numberofcourses = scanner.nextInt();
//Declaration
String ClassName[] = new String[numberofcourses];
String Description[] = new String[numberofcourses];
String Grade[] = new String[numberofcourses];
int Units[] = new int[numberofcourses];
//Arrays for class number, description, units, grade, grades point
//Here, input class number, description, units, and grades
for(int i = 0; i < numberofcourses; i++)
{
scanner.nextLine();
System.out.println("Please enter your #"+(i+1)+" class name: ");
ClassName[i] = scanner.nextLine();
System.out.println("Please enter your #"+(i+1)+" class description: ");
Description[i] = scanner.nextLine();
System.out.println("Please enter your #"+(i+1)+" class units: ");
Units [i] = scanner.nextInt();
System.out.println("Please enter your #"+(i+1)+" class grade: ");
Grade[i] = scanner.nextLine();
}
System.out.println("Class Grades - "+term+" Term");
System.out.println("Office Grades");
System.out.println("Class \t \t Description \t \t Units \t \t Grade \t \t Grade Points");
for(int i = 0; i < numberofcourses; i++)
{
System.out.println(ClassName[i]+"\t \t"+Description[i]+"\t \t"+Units[i]+"\t \t"+Grade[i]);
}
}
}
【问题讨论】: