Java找出三个整数中的最大值max和最小值min
输入
52 61 2
输出
Max=52
Min=2
package com;
import java.util.*;
public class app4_1 {
public static void main(String[] args)
{
int a,b,c,max,min;
Scanner reader=new Scanner(System.in);
System.out.println("请输入a、b、c数据:");
a=reader.nextInt();
b=reader.nextInt();
c=reader.nextInt();
if(a<b)
max=a;
else max=b;
if(c>max)
max=c;
System.out.println("Max="+max);
min=a<b?a:b;
min=c<min?c:min;
System.out.println("Min="+min);
}
}
例子(已填好数据)
public class app4_1 {
public static void main(String[] args)
{
int a=1,b=2,c=3,max,min;
if(a<b)
max=a;
else max=b;
if(c>max)
max=c;
System.out.println("Max="+max);
min=a<b?a:b;
min=c<min?c:min;
System.out.println("Min="+min);
}
}