无论如何重新排列数组列表并删除打印行
您好,我必须编写一个程序,其中包含候选人的数量以及他们从最好到最差的票数。我编写了两个不同的类来使用 fileInputStream 和另一个使用扫描仪类并将其存储在数组列表中的类来执行此操作,但老师将其存储在文本文件中的方式是一些选票位于不同的行上,因此它们会去就像在一条线上,而选票在另一条线上。所以它是这样的:
//this is how the text appears in the text file and I was wondering if I could get all
//the "votes" to look like the first one.
<v> 5 4 3 2 1
<v> 1 2 3 4 5
<v>
1
2
3
5
<v>
5
2
4
1
3
Hi I have to write a program that takes in number of candidate and how many votes they got from the best to the worst. And I wrote two different classes to do that using a fileInputStream and another that uses the scanner class and storing it in the arraylist but the way the teacher has it in the text file is that some of the ballots are on different line so they will go like on one line while the ballots are on the other line. so its like this:
//this is how the text appears in the text file and I was wondering if I could get all
//the "votes" to look like the first one.
<v> 5 4 3 2 1
<v> 1 2 3 4 5
<v>
1
2
3
5
<v>
5
2
4
1
3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的老师是故意的。这里的技巧是要意识到投票不是由新线分隔的,而是由“V”分隔的。您可以将此信息与 regex(Pattern< /a>) 得出解决方案。
I think your teacher has done it deliberately. The trick here is to realize that the votes are not delimited by a new line, instead they are delimited by a "V". You can use this information along with regex(Pattern) to derive a solution.
如果您不想使用正则表达式,可以使用 扫描仪。
例如:
我不想破坏你做作业的“乐趣”,仅此而已。如果您还有更多问题,请尽管提问。
If you don't want to use a regex, you could use Scanner.
This would read for example:
I don't want to spoil the 'fun' of making your homework, so that's all. If you have more questions, just ask.