Write a program that reads three integers, find the maximum and minimum number of

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); }
		 * 
		 * }
		 */
	}
}

Published 28 original articles · won praise 5 · Views 5784

Guess you like

Origin blog.csdn.net/weixin_41879980/article/details/104494881