Java代码段可使用多个测试用例和每个测试用例中的多个值来扫描以下输入

时间:2018-10-24 17:32:09

标签: java

我需要对一组正整数(任意数字/秒)执行Java操作(例如,为使操作更简单而加法。)

样本输入,其中第一行给出了测试用例的数量,下面的行是具有任意数量的正整数的相应测试用例

输入:

   <article id="article">
            <ol>
                <li>
                    <h1>New list of article(none-id).</h1>
                    <h2>second</h2>
                    <hr>
                </li>
                <li>
                    <h1>New list of article(none-id).</h1>
                </li>
                <li id="li-1">
                    <h1>Navigation to content of article.</h1>
                    <hr>
                    <ol>
                        <li id="">
                            <h1>Navigation to content of article 1-2</h1>
                            <hr>
                        </li>
                    </ol>
                </li>
                <li>
                    <h1>New list of article(none-id).</h1>
                    <hr>
                    <p>hello</p>
                </li>
                <li id="li-2">
                    <h1>Navigation to content of article 2</h1>
                    <hr>
                </li>
            </ol>
        </article>

输出:

3
67 8 12
3 6 9 78 6
4 6 13

1 个答案:

答案 0 :(得分:0)

首先,您需要读取文件,让我们使用public class Test { public static void main(String[] args) { //create grid int [] [] grid = new int [3][3]; grid [0][0] = 7; grid [1][0] = 8; grid [2][0] = 9; grid [0][1] = 4; grid [1][1] = 5; grid [2][1] = 6; grid [0][2] = 1; grid [1][2] = 2; grid [2][2] = 3; int rows = 3; int columns = 3; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { System.out.println(grid[i][j] + " "); } System.out.println(""); } } 。接下来,您需要阅读第一行,将其转换为7 4 1 8 5 2 9 6 3 ,现在您知道应该执行多少 job (或测试用例)了。接下来使用Files.readAllLines循环作业计数,并从文件中获取每一行。用int对其进行拆分,然后遍历所有值,将其转换为for并进行汇总。

代码:

space

file.txt:

int

P.S。下次当您提出问题时,请添加尝试/代码,以指定您尝试解决的问题。