键盘录入两个数据,返回两个数中的较大值:

import java.util.Scanner;
class Hello2 {
    public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
         System.out.println("请输入第一个整数");
         int x = sc.nextInt();
         System.out.println("请输入第二个整数");
         int y = sc.nextInt();
         int max = getMax(x,y);
         System.out.println("max = " + max);
    }

    public static int getMax(int a,int b) {
        int max = (a > b) ? a : b;
        return max;
    }
}

结果:

用方法来键盘录入两个数据,返回两个数中的较大值

相关文章:

  • 2021-07-26
  • 2021-11-23
  • 2021-12-26
  • 2021-07-10
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-12
  • 2021-09-01
  • 2022-12-23
  • 2021-11-10
  • 2021-08-15
  • 2022-02-03
相关资源
相似解决方案