- package Day16;
- public class Test2 {
- public static void main(String args[]) {
- int x = 4;
- String str="qqq";
- char ch='x';
- System.out.println("1:value is " +((x>4)?99.9:9)); //比较数为double型,被提升了.
- System.out.println("2:value is " +((x>4)?99:9)); // 输出int型9
- System.out.println("3:value is " +((x>4)?"xyz":9)); //输出字符串"9" 例:4+"";=="4";
- System.out.println("4:value is " +((x>4)?9.999999999999999:9));//比较数为double型,被提升了.
- System.out.println("5:value is " +((x>4)?str:9)); //同s.o.y()3
- System.out.println(ch); //输出字符串"x";
- System.out.println("6:value is " +((x>4)?ch:9));//你的原句:9被转换成字符数值输出
- System.out.println((char)9); //9
- System.out.println("--------------------");
- }
- }
- /*
- * 1:value is 9.0
- 2:value is 9
- 3:value is 9
- 4:value is 9.0
- 5:value is 9
- x
- 6:value is 9
- 6:value is
-
- --------------------
- */
复制代码 |