import java.util.Scanner;
public class Text2 {
/**
* 第2题: 要求: 写一个程序输入3个整数a,b,c,按从小到大顺序输出。
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个整数:");
int a = sc.nextInt();
System.out.println("请输入第二个整数:");
int b = sc.nextInt();
System.out.println("请输入第三个整数:");
int c = sc.nextInt();
/*int t1 = a > b ? a : b;
int max = t1 > c ? t1 : c;
if (max == a) {
if (b < c) {
System.out.println(b + "<"+ c + "<"+ a);
}else {
System.out.println(c + "<"+ b + "<"+ a);
}
}else if (max == b) {
if (a > c) {
System.out.println(c + "<"+ a + "<"+ b);
}else {
System.out.println(a + "<"+ c + "<"+ b);
}
}else {
if (a > b) {
System.out.println(b + "<"+ a + "<"+ c);
}else {
System.out.println(a + "<"+ b + "<"+ c);
}
}*/
/*int e;
if (a > b) {
e = a;
a = b;
b = e;
}else if (a > c) {
e = a;
a = c;
c = e;
}
if (b > c) {
e = b;
b = c;
c = e;
}*/
if (a > b) {
a = a ^ b;
b = a ^ b; //b = a ^ b ^ b;
a = a ^ b; //a = a ^ a ^ b;
} else if (a > c) {
a =a ^ c;
c = a ^ c;
a = a ^ c;
}
if (b > c) {
b = b ^ c;
c = b ^ c;
b = b ^ c;
}
System.out.println("三个数由小到大为:" + a +" "+ b +" "+ c);
}
} |
|