如何显示用户输入的整数数量?

huangapple go评论125阅读模式
英文:

How to display the numbers of integers that the user input?

问题

以下是翻译好的内容:

示例输出如下:

  1. [![在此输入图片描述][1]][1]
  2. int nValue, x;
  3. Scanner input = new Scanner(System.in);
  4. System.out.print("输入 n 的值:");
  5. nValue = input.nextInt();
  6. for (x = 1; x == nValue; x++){
  7. System.out.println("输入数字 " + x + ": ");
  8. }
  9. 非常感谢任何帮助。

请注意,为了使代码更加清晰,我稍微修改了代码中的一些表达方式。

英文:

Sample output is this 如何显示用户输入的整数数量?

  1. int nValue, x;
  2. Scanner input = new Scanner(System.in);
  3. System.out.print("Enter value of n: ");
  4. nValue = input.nextInt();
  5. for (x = 1; x == nValue; x++){
  6. System.out.println("Enter number" + x + ": ");

Any help is much appreciated.

答案1

得分: 1

不确定这是否完全回答了您所要问的问题,但它应该会给出示例输出:

  1. // 这里也不需要 x 变量
  2. int nValue;
  3. Scanner input = new Scanner(System.in);
  4. System.out.print("输入 n 的值:");
  5. nValue = input.nextInt();
  6. // 我们递增 x,直到达到 nValue
  7. for (int x = 1; x <= nValue; x++){
  8. System.out.println("输入数字 " + x + ":");
  9. }
英文:

Not sure if this answers exactly what you are trying to ask, but it should give the sample output:

  1. // also we dont need the x variable up here
  2. int nValue;
  3. Scanner input = new Scanner(System.in);
  4. System.out.print(&quot;Enter value of n: &quot;);
  5. nValue = input.nextInt();
  6. //we increment x, until we reach the `nValue`
  7. for (int x = 1; x &lt;= nValue; x++){
  8. System.out.println(&quot;Enter number&quot; + x + &quot;: &quot;);

答案2

得分: 0

  1. Scanner input = new Scanner(System.in);
  2. System.out.print("输入 n 的值:");
  3. int n = input.nextInt();
  4. System.out.print("输入 " + n + " 个整数:\n");
  5. System.out.print("输入数字 1:");
  6. int num1 = input.nextInt();
  7. System.out.print("输入数字 2:");
  8. int num2 = input.nextInt();
  9. System.out.print("输入数字 3:");
  10. int num3 = input.nextInt();
  11. System.out.print("输入数字 4:");
  12. int num4 = input.nextInt();
  13. System.out.print("输入数字 5:");
  14. int num5 = input.nextInt();
英文:
  1. Scanner input = new Scanner(System.in);
  2. System.out.print(&quot;Enter value of n: &quot;);
  3. int n =input.nextInt();
  4. System.out.print(&quot;Enter &quot; + n + &quot; integers: \n&quot;);
  5. System.out.print(&quot;Enter number 1:&quot;);
  6. int num1 = input.nextInt();
  7. System.out.print(&quot;Enter number 2:&quot;);
  8. int num2 = input.nextInt();
  9. System.out.print(&quot;Enter number 3:&quot;);
  10. int num3 = input.nextInt();
  11. System.out.print(&quot;Enter number 4:&quot;);
  12. int num4 = input.nextInt();
  13. System.out.print(&quot;Enter number 5:&quot;);
  14. int num5 = input.nextInt();

huangapple
  • 本文由 发表于 2020年9月20日 08:28:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63974512.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定