0

我正在处理一些需要输入文件并格式化文本的代码。我只发布了我的代码的主要部分。我试图找到最大行长,这是我的 else 语句开头的代码,它编译并运行得很好,但没有打印出“宽度”,似乎我有某种语法问题或我似乎无法弄清楚的东西。我有几个人查看了我的代码,但没有成功,这里有人有什么建议吗?

public static void main (String[] args) {
  int argix = 0;
  if (args.length == 0) {
    //There are no filenames given on the command line.
    out.printf ("FILE: -%n");
    format (new Scanner (in));  
  }else {
     // Iterate over each filename given on the command line.
     if(args[0].matches("-\\d+")){
       width=Integer.parseInt("-\\d+");
       width=width*-1;
       System.out.println(width);
       argix = 1;
     }
     for (; argix < args.length; ++argix) {
        String filename = args[argix];
        if (filename.equals ("-")) {
           // Treat a filename of "-" to mean System.in.
           out.printf ("FILE: -%n");
           format (new Scanner (in));
        }
        else {
           //Open the file and read it, or error out.
           try {
              Scanner infile = new Scanner (new File (filename));
              out.printf ("FILE: %s%n", filename);
              format (infile);
              infile.close();
           }catch (IOException error) {
              exit_status = EXIT_FAILURE;
              err.printf ("%s: %s%n", JAR_NAME,
                          error.getMessage());
           }
        }
     }
  }
  exit (exit_status);

}

4

0 回答 0