|
发表于 2018-5-5 16:16:23
|
显示全部楼层
public class MainClass{
public static void main(String args[]){
char ch1 = 'w',ch2 = '好';
int p1 = 32831,p2 = 30452;
/**数据类型转换由低到高**/
float x = 100;
int z = 50;
float y = z;
/**数据转换由高到低**/
int a = (int)34.89;
long b = (long)56.98F;
int c = (int)1999L;
int d = 128;
long e = 77777;
float f = 2e3f;
double g = 3.14e-300;
double result = f * g;
System.out.println("f = " + f);
System.out.println("g = " + g);
System.out.println("result = " + result);
g = 1234.123456789;
c = (int)d;
f = (float)g;
System.out.println("d = " + c);
System.out.println("e = " + e);
System.out.println("f = " + f);
System.out.println("g = " + g);
System.out.println(ch1 + "的位置:" + (int)ch1);
System.out.println("\"" +ch2 +"\"的位置:" + (int)ch2);
System.out.println("第" + p1 + "个位置上的字符是:" + (char)p1);
System.out.println("第" + p2 + "个位置上的字符是: " + (char)p2);
System.out.println(y);
System.out.println(x);
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
F:\abc>java MainClass
f = 2000.0
g = 3.14E-300
result = 6.28E-297
d = 128
e = 77777
f = 1234.1234
g = 1234.123456789
w的位置:119
"好"的位置:22909
第32831个位置上的字符是:耿
第30452个位置上的字符是: 直
50.0
100.0
34
56
128
|
|