写出一个程序读入三个整数,找出最大和最小的数

package exp12;

import java.util.Scanner;

public class exp12_2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("输入三个整数:");
		int one = sc.nextInt();
		int two = sc.nextInt();
		int three = sc.nextInt();
		int max, min;
		// 方法一
		int temp_max = (one >= two) ? one : two;
		max = (temp_max >= three) ? temp_max : three;
		System.out.println("最大值为:" + max);
		int temp_min = (one <= two) ? one : two;
		min = (temp_min <= three) ? temp_min : three;
		System.out.println("最小值为:" + min);

		// 方法二
		/*
		 * if(one>two) { max = one; min = two; if(max>three) {
		 * System.out.println("最大值为:"+max); }else { max = three;
		 * System.out.println("最大值为:"+max); } if(min>three) { min = three;
		 * System.out.println("最小值为:"+min); }else { System.out.println("最小值为:"+min); }
		 * }else { max = two; min = one; if(max>three) {
		 * System.out.println("最大值为:"+max); }else { max = three;
		 * System.out.println("最大值为:"+max); } if(min>three) { min = three;
		 * System.out.println("最小值为:"+min); }else { System.out.println("最小值为:"+min); }
		 * 
		 * }
		 */
	}
}

你可能感兴趣的:(Java)