- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个程序,我需要为飞机上的座位表制作方法对这个名字和姓氏列表进行排序。它是一个二维数组,第一列是名字,第二列是第一列对应人物的姓氏。我需要按姓氏、名字的字母顺序对其进行排序,但我不知道如何对姓氏进行排序,然后保留相应的姓氏。
这是我的代码:
package assignment_6_1;
import java.util.Scanner;
import java.util.Arrays;
public class Assignment_6_1 {
public static void main(String[] args) {
//Create a Scanner
Scanner input = new Scanner(System.in);
//Create int & string []
String[][]firstAndLastNames = new String[36][2];
int[]heightOfPerson = new int[36];
String[][]seatingChartDiagram = new String[9][4];
int[][]seatRequest = new int [36][2];
//Gather list of names and heights
for(int i=0; i<heightOfPerson.length; i++)
{
//Get first name
System.out.println("Enter Your First Name: ");
firstAndLastNames[i][0] = input.next();
//Get last name
System.out.println("Enter Your Last Name: ");
firstAndLastNames[i][1] = input.next();
//Get height in inches
System.out.println("Enter your height (Iches) : ");
heightOfPerson[i] = input.nextInt();
//Is there a seat request or not
System.out.println("Do you want to request a seat ?");
String ifSeatRequest = input.next();
//Get seat request
if(ifSeatRequest.equals("Yes") || ifSeatRequest.equals("yes"))
{
System.out.println("Enter the seat row you want: ");
seatRequest[i][0] = input.nextInt();
System.out.println("Enter the seat number you want in that row: ");
seatRequest[i][1] = input.nextInt();
}
else
{
//set the request colum for that person to 0 for no request
seatRequest[i][0] = 0;
seatRequest[i][1] = 0;
}
//Prints passenger manifest when list is full
if(firstAndLastNames[35][1] != null){
System.out.println("All Seats are Filled");
break;}
}
String[]firstNameSort = new String[36];
//put the first names into another array to sort
for(int j=0; j<heightOfPerson.length; j++)
{
firstNameSort[j] = firstAndLastNames[j][1];
}
//Alphabetize first name list
Arrays.sort(firstNameSort);
String[][]firstNameAlphLast = new String[36][2];
String[][]nameAlph = new String[36][2];
}
}
按顺序:它接收用户输入的 36 个姓名、高度以及用户是否想提出座位请求。我让它复制数组 2 另一个数组,然后我按字母顺序排列姓氏。现在我不知道如何为按字母顺序排列的姓氏获取相应的名字。
最佳答案
试试这个:-
Arrays.sort(firstAndLastNames, new Comparator<String[]>() {
@Override
public int compare(final String[] a1, final String[] a2) {
return a1[1].compareTo(a2[1]) + a1[0].compareTo(a2[0]);
}
});
关于java - 排序名字和姓氏数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28479689/
我有两个表,Table1和Table2。 Table1由格式为FullName的名称列('FirstName LastName')和唯一标识符(Key)组成。 Table2的列(Name)由这些名称组
我正在使用 ajax 实时搜索来选择名称和姓氏的串联与输入的文本匹配的所有用户,并且效果很好: $sql = "SELECT * FROM users WHERE concat(name,' ',su
我有一组采用 last, first 格式的名称 Name Pos Team Week.x Year.x GID.x h.a.x Oppt.x Week1Points DK.
我有一个函数,如果我有姓氏和名字,它应该返回 True。 此名称返回 False,但应返回 True。任何想法为什么?我希望能够在名称 A-Z、a-z、下划线和 0-9 中接受撇号。逗号前后可能有也可
我有一个 drupal 数据库,其中 node 表充满了配置文件。字段node.title是“Firstname Lastname”。我想分隔名称,以便 node.title = "Firstname
我正在使用 Django-Registration 包让用户创建帐户、对其进行身份验证并登录到我的 web 应用程序。 但是,用于创建帐户的表单/ View 不会要求用户提供名字/姓氏(这些字段是模型
我正在尝试使用云工具包获取用户的名字,但是以下代码未获取用户的名字,并且将firstNameFromFunction变量保留为空。有谁知道如何在iOS 10中实现这一目标? let container
运行应用程序时出现以下错误: 错误: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'pa
我想尝试在 Javascript 中检测一个人名字的不同部分,并将它们剪掉,以便我可以将它们传递给其他东西。 名称可以以任何格式出现——例如:- 维多利亚·米·莱恩小姐 Victoria C J Lo
这是我读过的教程中的查询 CREATE TABLE Employee ( id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, depa
所以我的程序有问题。如果我删除 in.nextLine,println 的名字和姓氏将一个接一个地打印,如果我有它,它不会在我的输出中打印名字,因为我认为它正在删除它。任何帮助将不胜感激。 impor
我专门使用omniauth来允许使用facebook/google/twitter登录到我的网站。 我存储名字,姓氏和电子邮件。但是,当我从oauth引发twitter auth哈希时,我仅在auth
我有一个看起来有点像这样的 df: name id John McNamara 3498 Jane Adams,
我有一个大数据集,我知道其中包含许多重复记录。基本上我有关于名字、姓氏、不同地址组成部分和出生日期的数据。 我认为最好的方法是使用姓名和出生日期,因为如果这些都匹配,则很可能是同一个人。可能有很多情况
我知道这是一件非常简单的事情,但我无法弄清楚我遗漏了什么或做错了什么。我认为这可能与 char 变量有关。这是我到目前为止所拥有的: #include #include "stdafx.h" #inc
我正在尝试使用以下代码获取电话联系人中所有可用联系人的详细信息。但面临重复值的小问题。 已编辑 实际代码开始:- private String refreshData() { Stri
我正在尝试实现对数据表的搜索。现在,我只能搜索名字、中间名和姓氏等。但是,在搜索全名(中间名和姓氏)时,搜索将不起作用。图像: success search for firtname/middle/l
Magento 是否可以通过客户的公司名称以及联系人姓名来查看/管理我们的客户,以便轻松找到他们?它用于 B2B,因此当电子邮件发出时,他们会提取客户的姓名,而不是更合适的公司名称。 这是全局设置吗?
我正在尝试实现对数据表的搜索。现在,我只能搜索名字、中间名和姓氏等。但是,在搜索全名(中间名和姓氏)时,搜索将不起作用。图像: success search for firtname/middle/l
我想检查用户输入的命令如: 添加人员关系人员(人员可以是例如 John 或“John Smith”) 示例:添加 John Smith 兄弟 Jack Smith... 我使用分隔符(空格)将字符串拆
我是一名优秀的程序员,十分优秀!