分析:需求:1、如果输入3个整数-a,b,c;
2、有相等的数,也得表示出来;
3、额外加个异常处理----处理输入数不符合要求的情况;
思考:直接使用Math类中的静态方法min()求两个数中最小数的时候,只返回一个值,无法进行甄别两个数是否相等,同时,无法让输出的结果直接体现2个数相等的情况----所以需要加条件判断;
代码实现:
public class demo6 { public static void main(String[] args) { System.out.println("请输入3个整数:"); Scanner sc=new Scanner(System.in); try{ int a= sc.nextInt(); int b=sc.nextInt(); int c= sc.nextInt(); //调用方法 min(a,b,c); }catch (InputMismatchException e){ System.out.println("输入的数不符合【3个整数】要求,请检查并重新输入!"); } } //方法-找出3个数中的最小数,有数相等的情况下,将相等的数都输出 public static void min(int a,int b,int c){ //1、求a与b中的最小数 int min=Math.min(a,b); //2、a,b两种