Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何跟踪整数并打印出以下语句?_Java_Loops_User Input_Number Sequence - Fatal编程技术网

Java 如何跟踪整数并打印出以下语句?

Java 如何跟踪整数并打印出以下语句?,java,loops,user-input,number-sequence,Java,Loops,User Input,Number Sequence,下面的代码是我能够创建的,但现在我不知道下一步该做什么 编写一个程序,读取整数输入序列并打印 这些数字的累计总数 输入的最小数字 输入的最大数字 偶数输入的数目 奇数输入的数目 您需要为此跟踪另一条信息的平均数 程序应该首先设置输入扫描器和变量,然后使用while循环请求用户输入并跟踪所需的数据。必须为用户指定一种停止输入的方式,可能是通过输入Q或Q。循环结束后,程序应打印问题的结果。到目前为止,数字的累计总数应在用户输入的每个数字之后打印。最小值、最大值、偶数、赔率和平均值只需在用户完成数字输

下面的代码是我能够创建的,但现在我不知道下一步该做什么

编写一个程序,读取整数输入序列并打印

这些数字的累计总数 输入的最小数字 输入的最大数字 偶数输入的数目 奇数输入的数目 您需要为此跟踪另一条信息的平均数 程序应该首先设置输入扫描器和变量,然后使用while循环请求用户输入并跟踪所需的数据。必须为用户指定一种停止输入的方式,可能是通过输入Q或Q。循环结束后,程序应打印问题的结果。到目前为止,数字的累计总数应在用户输入的每个数字之后打印。最小值、最大值、偶数、赔率和平均值只需在用户完成数字输入后打印。您需要if语句和模数来完成此任务。此程序的所有数字都应为整数。完成后,请在黑板上交上你们的注释代码。请确保您的姓名已在 代码的顶部

    //Asks user of a number
    System.out.print("Enter an integer: ");
    int num = 0;

    int num1;
    int num2;
    int num3;
    int num4;
    int num5;

    while (in.hasNextInt())
        {
        num = in.nextInt();

        System.out.print("Enter next integer or Q to quit ");
        }

    //Gets total of numbers

    //Gets smallest number

    //Gets largest number

    //Number of even inputs

    //Number of odd inputs

    //Gets average of numbers

你应该考虑使用一个数组或一个ARRAYISTIF,你不知道用户要输入的输入的数量。另外,while循环不应该在.hasNextInt中。您应该在.next中获取字符串并解析为整数,然后在循环中检查字符串和循环,直到字符串.equalsIgnoreCaseQ…希望这足以让您开始。我认为这是练习的一部分,不使用数组或其他动态数据结构,至少从我对这份工作的理解来看。此外,您不应该称自己为ints num1到num5,而应该给他们起像commuilativeSum这样的名字。