我是编程的新手。我为大学的编程课程做了以下项目。我们编写了一个迷你银行程序代码,每个客户都应该获得一个像“KU345-32”这样的ID。我使用以下代码生成这些ID:
int customerID = ThreadLocalRandom.current().nextInt(1, 100000);
char firstChar = (char)ThreadLocalRandom.current().nextInt(65, 91);
char secondChar = (char)ThreadLocalRandom.current().nextInt(65, 91);
custID= "" + firstChar + secondChar + (formatCID.format(customerID)).substring(0, 3) + "-" + (formatCID.format(customerID)).substring(3, 5);
这个bankprogram的一个任务是首先按字母顺序对这些ID进行排序,然后对数字进行排序:
AT234-12
BA123-08
等等。 但这怎么可能呢?对我来说没有问题删除 - 到处都是但我不知道如何比较或使用哪个界面。写一个自己可比的对我来说可能太多了。我期待着任何帮助:)
答案 0 :(得分:0)
如果我理解了你的帖子,你需要对你的" ID"进行排序。 char by char。
对于字符串按字母顺序排序,请仔细查看this topic。
然后在您自己的比较器中组合数字排序。那里没什么好玩的。祝你好运!