- /**
- 此程序用来诠释数据类型转换
- 思路:自动类型转换例子: 短整型转换成整型 单精度转换成双精度 字符型转换成整型
- 强制类型转换例子: 长整型转换成整型 整形转换成字节
- 步骤:
- 1.定义一个类
- 2.主函数
- 3.声明数据类型,赋值
- 4.转换并输出到屏幕
- */
- class Transformation
- {
- public static void main(String args[])
- {
- int x=4;
- short y=3;
- x=x+y;//整数=整数+短整数
- System.out.println("x="x);
- float a=3.1;
- double b=4.3;
- b=b+a;//双精度小数=双精度小数+单精度小数
- System.out.println("b="b);
- System.out.println('v'+2);//ASCLL码,字符转换成整数输出
- long m=6;
- int n=3;
- byte b=1;
- n=(int)(m+n);
- System.out.println('n'=n);//长整型转换成整型
- System.out.println('n'=(byte)(n+b));//整形转换成字节
- }
- }
复制代码
这个老是显示有4个错误,不知道怎么改,还有我这么诠释字符转换合适么,总觉得哪里不对,但是又说不出来。
|