LeetCode 面试题 16.07. 最大数值

题目

面试题 16.07. 最大数值

描述

编写一个方法,找出两个数字ab中最大的那一个。不得使用if-else或其他比较运算符。

解题思路

  1. 直接调用Math类自带的max()方法;

实现

package inteview;

import math.SixtyNine;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Version : 1.0
 * Author  : cunyu
 * Email   : [email protected]
 * Website : https://cunyu1943.github.io
 * Date    : 2020/3/23 12:42
 * Project : LeetCode
 * Package : inteview
 * Class   : SixteenZeroSeven
 * Desc    : 面试题 16.07. 最大数值
 */
public class SixteenZeroSeven {
	public static void main(String[] args) throws Exception {
		SixteenZeroSeven sixteenZeroSeven = new SixteenZeroSeven();
		int a = new Scanner(System.in).nextInt();
		int b = new Scanner(System.in).nextInt();
		System.out.println(sixteenZeroSeven.maximum(a, b));
	}

	public int maximum(int a, int b) {
		return Math.max(a, b);
	}
}

发布了138 篇原创文章 · 获赞 72 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/github_39655029/article/details/105046250