自从编写了一些代码以来,我有点坚持在某个部分之后要做什么。它应该通过 ArrayList 放置一个文本文件,然后用户应该能够输入团队名称,并且应该将他们在文本文件中弹出的次数加起来。但是对于我的生活,我一直坚持在我拥有的东西之后如何继续。
public static void main(String[] args) throws FileNotFoundException {
ArrayList<String> mlb = new ArrayList<String>();
Scanner fileReader = new Scanner(new File("WorldSeriesWinners.txt")); // Declares the scanner to read from the file.
int Count = 0;
Scanner keyboard = new Scanner(System.in);
String userInput;
while (fileReader.hasNext()){
// While loop to continue to read while there is another line.
mlb.add(fileReader.nextLine());
}
System.out.println("Enter a championship team you are looking up(1903-2009).");
userInput = keyboard.nextLine();
for(String team : mlb){ // Will run through the file and display the ArrayList.
if(team.contains(userInput))
System.out.println(team);