输入三个整数x,y,z,请把这三个数由小到大输出。
package wzs.arithmetics;
import java.util.Scanner;
/**
* 输入三个整数x,y,z,请把这三个数由小到大输出。
* @author wWX154783
*
*/
public class Test_wzs14
{
public static void main(String[] args)
{
System.out.println("请输入三个整数:");
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
System.out.println("比较前:a=" + a + ",b=" + b + ",c=" + c);
int temp;
if (a > b)
{
temp = a;
a = b;
b = temp;
}
if (a > c)
{
temp = a;
a = c;
c = temp;
}
if (b > c)
{
temp = b;
b = c;
c = temp;
}
System.out.println("比较后:a=" + a + ",b=" + b + ",c=" + c);
}
}
注意:三个if的顺序,不合理交换顺序结果不正确!