A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

键盘录入两个数据,返回两个数中的较大值;比较两个数是否相等
代码实现:
import java.util.Scanner;
class FunctionCompare
{
        public static void main(String[] args)
        {
                System.out.println("键盘录入两个数据");
                Scanner sc1 = new Scanner(System.in);
                int a = sc1.nextInt();
                Scanner sc2 = new Scanner(System.in);
                int b = sc2.nextInt();
                int max = getMax(a,b);//返回最大值
                System.out.println("max = " + max);
                String str = compare(a,b);
                System.out.println(str);
        }
        public static int getMax(int x,int y)
        {
                        return x > y ? x : y;
        }
        public static String compare(int x,int y)
        {
                return x == y ? x + "相等" + y : x + "不相等" + y;
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马