我已经建立了一个程序,但我想打印出第二个输入

时间:2015-09-10 03:54:48

标签: java

该程序平均了用户输入的数字,但我想把它带到另一个级别,我想打印出用户输入的第二个数字。我是否需要更改和重建程序,还是只输入简单的内容?

import java.util.*;

public class InputHere
{

    public static void main(String[] args)
    {
        Scanner scan= new Scanner(System.in);
        int num;
        int counter= 0;
        int average;
        int total= 0;

        System.out.println("Enter 2 Numbers");

        while(counter < 2)
        {
            num= scan.nextInt();
            total=total + num;
            counter++;
        }
        average= total/2;
        System.out.println("The average is " + average);
    } 

}   

1 个答案:

答案 0 :(得分:-2)

 import java.util.*;

public class InputHere {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num;
        int counter = 0;
        int average;
        int total = 0;

        System.out.println("Enter 2 Numbers");

        while (counter < 2) {
            num = scan.nextInt();
            if (counter == 1)
                System.out.println(num);
            total = total + num;
            counter++;
        }
        average = total / 2;
        System.out.println("The average is " + average);
    }

}