ZZULIOJ1038: 绝对值最大

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014543872/article/details/83551766

题目描述

输入3个整数,输出绝对值最大的那个数。 

输入

输入包含3个int范围内的整数,用空格隔开。 

输出

输出三个数中绝对值最大的数,单独占一行。若绝对值最大的数不唯一,则输出最先出现的那个。例如,若输入为1 -3 3,则输出为-3;若输入为1 3 -3则输出为3。 

样例输入

1 2 -3

样例输出

-3
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int x = input.nextInt();
		int y = input.nextInt();
		int z = input.nextInt();
		int max = x;
		if (Math.abs(y) > Math.abs(max)) 
			max = y;
		if (Math.abs(z) > Math.abs(max)) 
			max = z;
		
		System.out.println(max);
	}
}

猜你喜欢

转载自blog.csdn.net/u014543872/article/details/83551766