慕粉2258416217
2017-03-27 12:16
用布尔怎样比较3个任意数的大小呢,不考虑循环和其他没学过的知识
int a=40,b=21,c=12,d;
if(a>b){
d=a;
a=b;
b=d;
}
if(a>c){
d=a;
a=c;
c=d;
}
if(b>c){
d=b;
b=c;
c=d;
}
System.out.println("由小到大依次为:"+a+b+c)
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);
}
}
}
}
int a=12 ;
int b=23 ;
int c=3;
System.out.println(a>b);
System.out.println(a>c);
System.out.println(b>c);
Java入门第一季(IDEA工具)升级版
1165172 学习 · 17581 问题
相似问题