英文:
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 + ": ");
}
非常感谢任何帮助。
请注意,为了使代码更加清晰,我稍微修改了代码中的一些表达方式。
英文:
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("Enter value of n: ");
nValue = input.nextInt();
//we increment x, until we reach the `nValue`
for (int x = 1; x <= nValue; x++){
System.out.println("Enter number" + x + ": ");
答案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("Enter value of n: ");
int n =input.nextInt();
System.out.print("Enter " + n + " integers: \n");
System.out.print("Enter number 1:");
int num1 = input.nextInt();
System.out.print("Enter number 2:");
int num2 = input.nextInt();
System.out.print("Enter number 3:");
int num3 = input.nextInt();
System.out.print("Enter number 4:");
int num4 = input.nextInt();
System.out.print("Enter number 5:");
int num5 = input.nextInt();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论