Java ternary operator precedence ? Different outputs given

前端 未结 3 1107
轮回少年
轮回少年 2021-01-20 11:48

I have the below code producing this output (no space after -1) ==> \"1 3 -14 -15 -1\"

int [] arr = {1, 3, Integer.MAX_VALUE, 4         


        
3条回答
  •  忘掉有多难
    2021-01-20 12:15

    You missed to put the operation within parenthesis, so it is behaving weirdly, use below code,

    try{
            throw new ArithmeticException("Exception Testing...");
        }catch(Exception e){
            String msg = "First Statement : " + (e.getCause() != null ? e.getMessage() : null);
    
            System.out.println(msg);
         }
    

    In case you need any other help or explanation on this . Please let me know.

提交回复
热议问题