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

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

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

问题

以下是翻译好的内容:

示例输出如下:

[![在此输入图片描述][1]][1]

int nValue, x;
Scanner input = new Scanner(System.in);

System.out.print("输入 n 的值:");
nValue = input.nextInt();

for (x = 1; x == nValue; x++){
    System.out.println("输入数字 " + x + ": ");
}

非常感谢任何帮助。

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

英文:

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

int nValue, x;
    Scanner input = new Scanner(System.in);

    System.out.print("Enter value of n: ");
    nValue = input.nextInt();

    for (x = 1; x == nValue; x++){
        System.out.println("Enter number" + x + ": ");

Any help is much appreciated.

答案1

得分: 1

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

// 这里也不需要 x 变量
int nValue;
Scanner input = new Scanner(System.in);

System.out.print("输入 n 的值:");
nValue = input.nextInt();

// 我们递增 x,直到达到 nValue
for (int x = 1; x <= nValue; x++){
    System.out.println("输入数字 " + x + ":");
}
英文:

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

// also we dont need the x variable up here
int nValue;
    Scanner input = new Scanner(System.in);

    System.out.print(&quot;Enter value of n: &quot;);
    nValue = input.nextInt();

    //we increment x, until we reach the `nValue`
    for (int x = 1; x &lt;= nValue; x++){
        System.out.println(&quot;Enter number&quot; + x + &quot;: &quot;);

答案2

得分: 0

Scanner input = new Scanner(System.in);

System.out.print("输入 n 的值:");
int n = input.nextInt();
System.out.print("输入 " + n + " 个整数:\n");

System.out.print("输入数字 1:");
int num1 = input.nextInt();
System.out.print("输入数字 2:");
int num2 = input.nextInt();
System.out.print("输入数字 3:");
int num3 = input.nextInt();
System.out.print("输入数字 4:");
int num4 = input.nextInt();
System.out.print("输入数字 5:");
int num5 = input.nextInt();
英文:
Scanner input = new Scanner(System.in);
        
        System.out.print(&quot;Enter value of n: &quot;);
        int n =input.nextInt();
        System.out.print(&quot;Enter &quot; + n + &quot; integers: \n&quot;);
        
        System.out.print(&quot;Enter number 1:&quot;);
        int num1 = input.nextInt();
        System.out.print(&quot;Enter number 2:&quot;);
        int num2 = input.nextInt();
        System.out.print(&quot;Enter number 3:&quot;);
        int num3 = input.nextInt();
        System.out.print(&quot;Enter number 4:&quot;);
        int num4 = input.nextInt();
        System.out.print(&quot;Enter number 5:&quot;);
        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:

确定