Java日志第46天 2020.8.21
例2.1 将字符赋给整型变量
public class Demo2_1 {
public static void main(String[] args) {
int i, j;
i = 'A';
j = 'B';
System.out.println(i+ " " + j);
}
}
例2.2 字符数据与整数进行算术运算。下面程序的作用是将小写字母转换为大写字母。
public class Demo2_2 {
public static void main(String[] args) {
char c1, c2;
c1 = 'a';
c2 = 'b';
c1 = (char) (c1-32);
c2 = (char) (c2-32);
System.out.println(c1 + " " + c2);
}
}
例2.3 符号常量的使用
public class Demo2_3 {
public static void main(String[] args) {
final int PRICE = 30;
int num = 10;
int total;
total = num * PRICE;
System.out.println("total = "+total);
}
}
例2.4 强制类型转换
public class Demo2_4 {
public static void main(String[] args) {
float x;
int i;
x = 3.6f;
i = (int) x;
System.out.println("x = "+x+",i = "+i);
}
}
例2.5 将有符号数据传送给无符号变量