问答详情
源自:3-8 Java中运算符的优先级

3个int整数比较大小?

用布尔怎样比较3个任意数的大小呢,不考虑循环和其他没学过的知识

提问者:慕粉2258416217 2017-03-27 12:16

个回答

  • MEMORY_WITH_U
    2017-03-27 13:39:53

    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)

  • qq_放浪形骸_2
    2017-03-27 13:19:36

    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);

    }

    }

    }

    }


  • 疯猿小白
    2017-03-27 12:57:45

    int  a=12 ;

    int  b=23 ;

    int  c=3;

    System.out.println(a>b);

    System.out.println(a>c);

    System.out.println(b>c);