我已经得到了平均值,并且我的程序已经从用户那里读取了三个整数,我的问题是我不知道如何获得程序的最大和最小数字:(
-我是编程新手 :(
这是我的程序:
主类:
import java.util.Scanner;
public class TestNumbers {
public static void main (String[]args){
int n1, n2, n3;
System.out.println("Enter three integer numbers ");
Scanner in = new Scanner(System.in);
n1 = in.nextInt();
n2 = in.nextInt();
n3 = in.nextInt();
Numbers num=new Numbers();
num.setNum(n1, n2, n3);
System.out.println("The Maximum of : "+n1+ " , " +n2+ " , " +n3+ " is ");
System.out.println("The Minimum of : "+n1+ " , " +n2+ " , " +n3+ " is ");
System.out.println("The Average of : "+n1+ " , " +n2+ " , " +n3+ " is "+num.getAve());
System.out.println("Press any key to continue...");
}
}
基类:
public class Numbers {
private int n1;
private int n2;
private int n3;
private int ave;
public void setNum(int n1, int n2, int n3){
this.n1=n1;
this.n2=n2;
this.n3=n3;
}
public double getAve(){
ave=(n1+n2+n3)/3;
return ave;
}
}