【发布时间】:2019-05-11 21:00:55
【问题描述】:
查看我的代码,我怎样才能让文本“输入 3 个课程系列,每行编码一个系列”,而“大小”和“已排序”具有不同的文本样式并带有下划线,以便于阅读?提前谢谢你。
public static void main(String[] args) {
LinkedList<String> ListofCourses = new LinkedList<>();
Scanner course = new Scanner(System.in);
String line;
String[] codes;
System.out.println("Ron's Copy");
System.out.println("\nEnter 3 collections of course codes one collection per line");
/**The 'for' statement is used here to output the user input of courses
and loop back to have the user enter another set of courses until the user
input has been completed 3 times successfully */
for (int i = 0; i < 3; i++) {
line = course.nextLine();
codes = line.split(" ");
//This statement adds input from sets
ListofCourses.addAll(Arrays.asList(codes));
//Sorting LinkedList with Collections.sort() method
Collections.sort(ListofCourses);
/*
* The system.out.print statement print out the courses in a sorted
* method and then loops back again to have the user input
*/
System.out.print("\nSize: " + ListofCourses.size() + " Sorted: ");
//The statements below will print sorted courses that were inputted by the user
for (int r = 0; r < ListofCourses.size(); r++) {
System.out.print(ListofCourses.get(r) + " ");
}
System.out.println();
//clear the list so that next iteration gets a fresh empty list
ListofCourses.clear();
}
}
【问题讨论】:
-
Razro 你在代码中添加了什么?
-
我认为他只是试图修复格式。您的某些代码不在代码表单内。
-
你不能,你需要使用 JTextPane 为它制作一个自定义 GUI。
-
谢谢 Samz,这就是我试图不做的事情,所以我将保持原样。谢谢大家的意见。
-
评论:您的问题标题没有帮助。标题实际上应该告诉读者问题是关于什么的。在这种情况下,您要问的问题与数组列表或排序无关。它实际上是关于修改控制台输出的样式/字体特征。
标签: java sorting linked-list