发布网友 发布时间:2022-04-23 21:17
共2个回答
热心网友 时间:2023-10-09 22:06
public class Number {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println("请输入3个整数!");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
MyMath(a, b, c);
}
public static int max(int a, int b, int c){
int m;
if (a > b)
m = a;
else
m = b;
if (m > c)
m = m;
else
m = c;
return m;
}
public static int min(int a, int b, int c){
int n;
if (a < b)
n = a;
else
n = b;
if (n < c)
n = n;
else
n = c;
return n;
}
public static int sum(int a, int b, int c){
int s;
s = a + b + c;
return s;
}
public static int avg(int a, int b, int c){
int v;
v = (a + b + c)/3;
return v;
}
public static void MyMath(int a, int b, int c){
int m = max(a, b, c);
int n = min(a, b, c);
int s = sum(a, b, c);
int v = avg(a, b, c);
System.out.println("最大的数为:"+m);
System.out.println("最小的数为:"+n);
System.out.println("和为:"+s);
System.out.println("平均值为:"+v);
}
}
热心网友 时间:2023-10-09 22:07
class MathTest
{
public static void main(String[] args)
{
int num1 = 23; //可随意更改
int num2 = 101;//可随意更改
int num3 = 53; //可随意更改
System.out.println("最大值" + MyMath.max(num1,num2,num3));
System.out.println("最小值" + MyMath.min(num1,num2,num3));
System.out.println("和" + MyMath.sun(num1,num2,num3));
System.out.println("平均数" + MyMath.average(num1,num2,num3));
}
}
class MyMath
{
static int max(int num1,int num2,int num3)
{
if(num1 > num2)
{
if(num1 > num3)
{
return num1;
}
}
else
{
if(num2 > num3)
{
return num2;
}
else
{
return num3;
}
}
return 0;
}
static int min(int num1,int num2,int num3)
{
if(num1 < num2)
{
if(num1 < num3)
{
return num1;
}
}
else
{
if(num2 < num3)
{
return num2;
}
else
{
return num3;
}
}
return 0;
}
static int sun(int num1,int num2,int num3)
{
return num1 + num2 + num3;
}
static double average(int num1,int num2,int num3)
{
return sun(num1,num2,num3)/3;
}
}