class DataDemo11{
public static void main(String args[]){
float f = 30.3f ; // 浮点型
int x = (int) f; // 强制类型转换
System.out.println("x = " + x) ;
System.out.println("10 / 3 = " + ((float)10 / 3)) ; // 执行强制转换
}
};结果是:str = lixinghua30
为什么???求解释??

解决方案 »

  1.   

    执行了 完全能没问题! 不知道你的问题出现在那里!    执行结果:     System.out.println("x = " + x) ;                           x = 30
         System.out.println("10 / 3 = " + ((float)10 / 3)) ;        10 / 3 = 3.3333333
      

  2.   

    不好意思贴错了,class DataDemo09{
    public static void main(String args[]){
    String str = "lixinghua" ; // 定义字符串变量
    int x = 30 ;
    str = str + x ; // 修改str的内容并将内容重新给str变量
    System.out.println("str = " + str) ;
    }
    };
      

  3.   


    str = str + x;//x会自动转化成String再与str相+,即连接字符串
      

  4.   

    想知道你要什么结果! 这样的结果有什么不对的吗?
     
              str = “lixianghua”+ "int x = 30";
              str = "lixianghua30" ? 
      

  5.   

    int x = 30 ;
    str = str + x ; // 修改str的内容并将内容重新给str变量
    ==================================================
    因为x与String类型相加时,会默认将x转意成包装类(Integer)
    通过Integer的toString方法将x转成String类型
    此时str与"30"相加得出你的结果。