小编Dan*_*mer的帖子

为什么 Integer.parseInt 在我的 java 代码中不起作用?

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

public class MainProgram {
   public static void main(String[] args ) throws IOException{
    String seconds = " ";

     Scanner sc2 = null;
        try {
            sc2 = new Scanner(new File("/Users/mohammadmuntasir/Downloads/customersfile.txt"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();  
        }

        boolean first = true;
        while (sc2.hasNextLine()) {
                Scanner s2 = new Scanner(sc2.nextLine());    
            while (s2.hasNext()) {
                String s = s2.next();
                if (first == true){
                    seconds = s;
                    first = false;
                }

            }
        }
        System.out.println(Integer.parseInt(seconds)); // causes ERROR?

     } …
Run Code Online (Sandbox Code Playgroud)

java parseint java.util.scanner

2
推荐指数
1
解决办法
9118
查看次数

标签 统计

java ×1

java.util.scanner ×1

parseint ×1