判断两数之间的最大值

判断两数之间的最大值

可直接利用Java自带的函数(abc 绝对值函数)再结合三元运算符实现

public class TestMax {

	public static void main(String[] args) {
		
		System.out.println(max(5,6));
		
	}

	private static int max(int i, int j) {
		// TODO Auto-generated method stub
		//	abc 绝对值函数
		return Math.abs(i-j)==(i-j)?i:j;
	}
	
}
发布了46 篇原创文章 · 获赞 61 · 访问量 3280

猜你喜欢

转载自blog.csdn.net/hyx1249273846/article/details/102869411