该程序平均了用户输入的数字,但我想把它带到另一个级别,我想打印出用户输入的第二个数字。我是否需要更改和重建程序,还是只输入简单的内容?
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);
}
}
答案 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);
}
}