3个int整数比较大小?
用布尔怎样比较3个任意数的大小呢,不考虑循环和其他没学过的知识
用布尔怎样比较3个任意数的大小呢,不考虑循环和其他没学过的知识
2017-03-27
import java.util.*;
public class ThreeCompare {
public static void main(String[] args) {
int a, b, c;
Scanner input = new Scanner(System.in);
System.out.println("请输入三个整数:");
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
if (a > b) {
if (a > c) {
if (b > c) {
System.out.println(c + "<" + b + "<" + a);
} else {
System.out.println(b + "<" + c + "<" + a);
}
} else {
System.out.println(b + "<" + a + "<" + c);
}
} else {
if (a > c) {
System.out.println(c + "<" + a + "<" + b);
} else {
System.out.println(a + "<" + b + "<" + c);
}
}
}
}
举报