A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 15114111253 中级黑马   /  2016-7-28 18:56  /  1029 人查看  /  7 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

获取三个数据中的最大值

7 个回复

倒序浏览
x>y?(x>z?x:z):(y>z?y:z);
回复 使用道具 举报
public class Test11 {
        public static void main(String[] args) {
        int x = 231,y=307,z=342;
        int temp;
        temp = x>y?x:y;
        int max;
        if(temp<z) {
                max = z;
        }else{
                max = temp;
        }
        System.out.println("最大值为:"+max);
}
}
回复 使用道具 举报
大天 发表于 2016-7-28 20:37
public class Test11 {
        public static void main(String[] args) {
        int x = 231,y=307,z=342;

哈哈  谢谢了
回复 使用道具 举报
int temp=(a>b)?a:b;
max=(temp>c)?temp:c;
回复 使用道具 举报
x>y?(x>z?x:z):(y>z?y:z);
回复 使用道具 举报
class Max{
     public static void main(String [] args){
          int a = 10;
          int b = 20;
          int c = 30;
          if (a>b & a>c){
            System.out.println(a);
                        } else if (b>a & b>c) {
                                 System.out.println(b);
                        }else
                                 System.out.println(c);
                        }
     }
回复 使用道具 举报
class Demo{
        public static void main(String[] args){
                int a = 1;
                int b = 2;
                int c = 3;
                int max = (((a > b) ? a : b) > c) ? ((a > b) ? a : b) : c;
                System.out.println("最大值为" + max);
       
        }
}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马