Java 扫描仪没有拾取文件的内容?

Java 扫描仪没有拾取文件的内容?,java,arraylist,java.util.scanner,Java,Arraylist,Java.util.scanner,我的程序中有一个小问题/错误,无法正确扫描内容。 我相信我使用的是正确的命令? 示例:java家庭作业5 hwk5sample1.txt 为什么不扫描任何内容并将其存储在myArrayList import java.io.*; import java.util.*; import java.lang.*; public class homework5 { public static int penny = 1; public static int nickle = 5; pub

我的程序中有一个小问题/错误,无法正确扫描内容。 我相信我使用的是正确的命令? 示例:
java家庭作业5 hwk5sample1.txt
为什么不扫描任何内容并将其存储在my
ArrayList

import java.io.*;
import java.util.*;
import java.lang.*;

public class homework5 {

  public static int penny = 1;
  public static int nickle = 5;
  public static int dime = 10;
  public static int quarter = 25;
  public static int halfDollar = 50;
  public static int dollar = 100;
  public static int change;

  public static void main(String[] args)
    throws FileNotFoundException {

    ArrayList<Integer> coinTypes = new ArrayList<Integer>();

    File f = new File (args[0]);
    Scanner input = new Scanner(f);
       while (input.hasNextInt()) {
            System.out.println("Found next int"); //used for debugging
            int i = input.nextInt();
            coinTypes.add(i);
            if (input.hasNextLine()) {
               change = input.nextInt();
                System.out.println("Found change"); //used for debugging
                System.out.println("Change: " + change);
            }
       }
    System.out.println(coinTypes); //used for debugging
  }
}
这是我在命令中使用的
hwk5sample1.txt
文件

// Coins available in the USA, given in cents.  Change for $1.43?
1 5 10 25 50 100
143
感谢您的任何帮助!多谢各位


编辑在我的作业描述中,它需要能够忽略类似的注释,并且仍然有效,因为测试人员将使用类似的文件

添加一个
input.nextLine()
来读取注释行

代码 输出
如果从文本文件顶部删除注释,会发生什么情况?
hasNextInt()
检查文件/输入中的下一个字符是否为整数。“//”不是整数,因此
hasnetint()
返回
false
然后它就工作了,不是我想要的,但这不是当前的问题。捕获在项目描述中,它必须能够忽略文件中的任何注释。我现在要把它添加到我的问题中
1)
抓取一整行
2)
检查它是否有int
3)
如果没有int,移动到下一行。好的,这就成功了谢谢!我会在可能的时候接受这个答案
// Coins available in the USA, given in cents.  Change for $1.43?
1 5 10 25 50 100
143
input.nextLine();
while (input.hasNextInt()) {
    System.out.println("Found next int"); // used for debugging
    int i = input.nextInt();
    coinTypes.add(i);
    if (input.hasNextLine()) {
        change = input.nextInt();
        System.out.println("Found change"); // used for debugging
        System.out.println("Change: " + change);
    }
}
Found next int
Found change
Change: 5
Found next int
Found change
Change: 25
Found next int
Found change
Change: 100
Found next int
[1, 10, 50, 143]