类型转换代码

public class J {
@SuppressWarnings("unused")
public static void main(String[] args) {
int i = 786;
byte b = (byte) i;
short s = (short) i;
System.out.println(b);
System.out.println(s);

int x = (int)3.6;
System.out.println(x);

//自动转换 赋值运算
long l = 7;//7默认为整型 int->long
int i1 = 5;
int i2 = 6;
char c = 'A';
System.out.println(l+i1+i2+c);
//强制类型转换
int i3 = (int)7l;//long-->int

int i4 = 5;
int j = 0;
int result1 = i4++ +j;//result=i4+j i4=i4+1 i4=6
int result2 = ++i4 +j;//i4=i4+1 result=i4+j
System.out.println(result1);
System.out.println(result2);
int j1 = 6;
int i5 = 4;
System.out.println(i5*=j1+4);
//多目运算符(三目运算符)
int mm;
System.out.println(5>7?mm=3:(mm=2));

int left=10;
int right=8;
int mid;
System.out.println("左手的牌是:"+left);
System.out.println("右手的牌是:"+right);
System.out.println("开始交换手里的牌");
mid = left;
left = right;
right = mid;
System.out.println("左手的牌是:"+left);
System.out.println("右手的牌是:"+right);



}
}

posted @ 2016-11-03 13:49  造西  阅读(160)  评论(0编辑  收藏  举报