Monday, September 22, 2014

Ternary type must match


// data types in ternary must match

public class TernaryTest {
   
    public static void main(String[] args){
        int i = 80;
        String s1 = String.valueOf(i<90?90:100);
        String s2 = String.valueOf(i<90?90:100.0); // 90 converted to 90.0
       
        System.out.println("s1="+s1);
        System.out.println("s2="+s2);
    }

}

OUTPUT
s1=90
s2=90.0

No comments:

Post a Comment