-5

在给定的代码中,

输入:
1
7

输出:
1

输出应该是 7。我错过了什么?

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

class compiler 
{
    public static void main(String args[] ) throws Exception 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int testcases = Integer.parseInt(br.readLine());

        //  System.out.println("If this statement is added it works as expected!")

        int n=Integer.parseInt(br.readLine());

        System.out.println(n);
    }
}

*我也尝试使用扫描仪

4

3 回答 3

1

这应该有效。如果您没有使用 IDE,那么也许您更改了代码并且没有再次编译。所以您实际上是在运行具有不同输出的旧代码?

于 2014-02-08T21:41:18.283 回答
0

事实上,在运行您的代码后,testcases将分别为 1 和n7(这将打印在控制台上 - 您的示例与给定的输出不匹配)。

也许这段代码将有助于将最后给定的输入打印到输出:

int n;
while(br.readLine())
{
    n=Integer.parseInt(br.readLine());
}
System.out.println(n);
于 2014-02-08T21:34:16.177 回答
-3
 The code must be like this if you want to use command line argument
 Public static void main(String ar[])
 {

  int i=(0;
  for(i=0;i<ar.length;i++)
  System.out.println(" "+ar[i]);

    }
于 2014-02-08T21:31:30.937 回答