如何使用Arrays.sort以字母顺序输出名称?

问题描述

我基本上想使用Arrays.sort()方法按字母顺序对学生的姓名进行排序,然后将其写入名为class SomeWidget(QtWidgets.QWidget): def __init__(self,parent=None): super().__init__(parent) layout = QtWidgets.QVBoxLayout(self) # ... 的新文本文件中。我尝试这样做,但这会给我一个错误,我不知道我是在正确地起诉它还是放在正确的位置。

样本输入:

StudentNames

样本输出

Select Your Class Size!

A 6x5 Classroom or a 3X10 classroom?
 Enter '6x5' or '3x10' please!

6x5

Ok,so you have selected 6x5
Your classroom size looks like this:

XXXXXX
XXXXXX
XXXXXX
XXXXXX
XXXXXX

Now Enter The Number Of Students!
4

Enter the names of the 4 students!

Hussain
User
Jacob
Bob

The Student Names Have Been Sorted In An Alphabetical Order
The Names And Seat Location Of The Student Are As Follows:

Hussain Seat Location: (1)(1)
User Seat Location: (1)(2)
Jacob Seat Location: (1)(3)
Bob Seat Location: (1)(4)

我得到的输出: 选择您的班级人数!

Select Your Class Size!

A 6x5 Classroom or a 3X10 classroom?
 Enter '6x5' or '3x10' please!

6x5

Ok,so you have selected 6x5
Your classroom size looks like this:

XXXXXX
XXXXXX
XXXXXX
XXXXXX
XXXXXX

Now Enter The Number Of Students!
4

Enter the names of the 4 students!

Hussain
User
Jacob
Bob

The Student Names Have Been Sorted In An Alphabetical Order
The Names And Seat Location Of The Student Are As Follows:

Bob Seat Location: (1)(1)
Hussain Seat Location: (1)(2)
Jacob Seat Location: (1)(3)
User Seat Location: (1)(4)

基本上它什么都没有输出,我评论了我的A 6x5 Classroom or a 3X10 classroom? Enter '6x5' or '3x10' please! 6x5 Ok,so you have selected 6x5 Your classroom size looks like this: XXXXXX XXXXXX XXXXXX XXXXXX XXXXXX Now Enter The Number Of Students! 4 Enter the names of the 4 students! Hussain The Student Names Have Been Sorted In An Alphabetical Order The Names And Seat Location Of The Student Are As Follows: 打印语句,这样它会显示我会得到的错误,但什么都不输出

代码

catch

解决方法

我相信BeUndead要说的是:

  // Output the first names in the 
  for (int x = 0; x < numOfStudents; x++) {
      names[x] = inp.next();
  }

  Arrays.sort(names); // This is where I put it,but it wouldn't work

  for (int x = 0; x < numOfStudents; x++) {
      if(containsx) {
          if(row >= 6) {
              column++;
              row = 0;
          }
      }
      else {
          if(row >= 3) {
              column++;
              row = 0;
          }
      }
      seats[x] = "("+Integer.toString(column)+")" + "("+Integer.toString(++row)+")";
      bw.write(Arrays.toString(names)+" Seat Location: "+seats[x]);
      bw.newLine();
  }

但是,您必须了解,这只是一个起点。您的代码中还有更多错误。进行更改,检查结果,然后再次询问更具体的问题。