我通过stdin提交以下输入:

4 2

30个

30两

15三

25四

我的代码是:

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

        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String submittedString;
        System.out.flush();
        submittedString = stdin.readLine();

        zipfpuzzle mySolver = new zipfpuzzle();
        mySolver.getTopSongs(submittedString);

    }


哪个调用:

//Bringing it all together
    public String getTopSongs(String myString) {

        setUp(myString);
        calculateQuality();
        qualitySort();
        return titleSort();

    }


哪个电话

public void setUp(String myString) {

    String tempString = myString;

    //Creating array where each element is a line
    String[] lineExplode = tempString.split("\\n+");

    //Setting up numSongsAlbum and songsToSelect
    String[] firstLine = lineExplode[0].split(" ");
    numSongsAlbum = Integer.parseInt(firstLine[0]);
    songsToSelect = Integer.parseInt(firstLine[1]);

    System.out.println(lineExplode.length);
//etc
}


但是,由于某种原因,lineExplode.length返回值1 ...有什么建议吗?

亲切的问候,
达里奥

最佳答案

String[] lineExplode = tempString.split("\\n+");


String#split的参数是一个包含正则表达式的字符串

09-12 21:08