我无法让这个程序正确运行。我所有的答案,最小值,最大值,平均值都是零。我知道我一开始就将它们初始化为零,但是它们应该通过代码进行更改吗?
public static void main(String[] args) {
// TODO Auto-generated method stub
int a,b;
int max;
double average;
int min;
int total;
max=0;
min=0;
total=0;
Scanner keyboardInput = new Scanner(System.in);
System.out.println(" Enter a number :");
a = keyboardInput.nextInt();
System.out.println(" You entered :"+ a);
if (a>=0)
{a=max;
max=min;}
total=a;
System.out.println(" Max and min are "+ max +" & " + min + " The total and average is :" +total + " & "+a);
System.out.println(" Enter a second number");
b = keyboardInput.nextInt();
System.out.println(" You entered :"+ b);
if (b>=a)
{b=max;}
if (b<=a)
{b=min;}
average= (a+b)/2;
total= a+b;
System.out.println(" Max and min are "+ max + " & " + min + " and the total & average are :" +total + " & " +average +" respectively.");
//c = keyboardInput.nextDouble();
}
}
输出:输入一个数字:
2
您输入:2
最大值和最小值为 0 & 0 总和平均值为 :0 & 0
输入第二个数字
3
您输入:3
最大值和最小值分别为 0 和 0,总和平均值分别为:0 和 0.0。