这只是为了形式/整洁。反叛t(\ t),这是我所知道的,似乎不能很好地工作。这是我的代码:
import java.util.Scanner;
public class RegisterStudent {
public static void register() {
System.out.println("----------------------------------------");
System.out.println("Student Class Card Evaluation System");
System.out.println("----------------------------------------");
System.out.println("Personal Data");
Scanner input = new Scanner(System.in);
System.out.print("\tEnter student no.: ");
long studNo = input.nextLong();
System.out.print("\tEnter first name: ");
String fName = input.next();
System.out.print("\tEnter last name: ");
String lName = input.next();
System.out.print("\tEnter course: ");
String course = input.next();
System.out.println();
System.out.println("----------------------------------------");
System.out.println("Subject: Computer Programming 2");
System.out.println("----------------------------------------");
System.out.println();
System.out.print("\tPrelim Grade: ");
double pg = input.nextDouble();
System.out.print("\tMidterm Grade: ");
double mg = input.nextDouble();
System.out.print("\tPrefinal Grade: ");
double pfg = input.nextDouble();
System.out.print("\tFinal Grade: ");
double fg = input.nextDouble();
System.out.println();
System.out.println("----------------------------------------");
double gwa = (pg + mg + pfg + fg)/4;
System.out.println();
System.out.println("Student Evaluated successfully...");
System.out.println("Viewing Report...");
System.out.println();
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("ID No.\t\t" + "LASTNAME\t\t" + "FIRSTNAME\t\t" + "COURSE\t\t"
+ "PG\t\t" + "MG\t\t" + "PFG\t\t" + "FG\t\t" + "GWA");
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println(studNo + "\t\t" + lName + "\t\t" + fName + "\t\t" + course + "\t\t"
+ pg + "\t\t" + mg + "\t\t" + pfg + "\t\t" + fg + "\t\t" + gwa);
输出应该如下所示: output http://i47.tinypic.com/2zf66uu.jpg
用户输入的所有内容都应正确对齐。请帮我修复我的程序,谢谢你们!
我目前的输出是这样的: IMG http://i45.tinypic.com/23suf7p.png 你看它没有正确对齐
答案 0 :(得分:6)
由于这是作业,这里有几个提示:
printf
或PrintWriter
类上的PrintStream
方法可以进行对齐。 String.format
和Formatter
类也可以。
如果您希望对齐是可移植的,请不要在简单文本输出中使用TAB字符(即'\t'
)进行对齐。不同的操作系统对TAB的“宽度”有不同的看法。
答案 1 :(得分:0)
每行输入所需的标签数量将由首先出现在该行上的提示文本的长度确定,即提示越短,所需的标签越多。简单的试验和错误应该整理您的输出,以便为您提供所需的结果。