java 随堂笔记(3.16)
变换常量
转换型
public class 转换{
public static void main(String[] args){
double d = 10;// 10是int变量,占4个字符赋值双精度浮点型变量为8个字节
// 10会自动变10.0
System.out.println(d)
byte b = 20;
short s = b;
int i = b;
char c = 'a';
int i2 = c;
// c = b
// 强制类型转换
int e = (int)88.88;
System.out.println(e)
}
}
算术运算符
public class 运算符{
public static main void(String[] args){
int a = 5;
int b = 2;
System.out.println(a+b)
System.out.println(a-b)
System.out.println(a*b)
System.out.println(a/b)
System.out.println(a%b)
System.out.println("----------------")
// 整数与整数运算结果只能是整数,结果要有小数就要
// float参与
// 除法的结果就是商,取余的结果只能是余数
// ++ 就是变量的自增
// 单独使用
int c = 10;
/**
*c++;//10
*++c://11
*System.out.println(c);
*参与运算
*int d = c++;//++在变量的后面,先拿变量参与(赋 *在哪变量自增
*d = 10,d = 11
*/
int d = ++c;//++在变量前面,先拿变量自增,在拿 参与运算(赋值)
// c = 11, d = 11
System.out.println("c:"+c);//11
System.out.println("d:"+d);//11
System.out.println("----------------");
// 赋值运算符:= 将“=”右边的赋值给左边
int e = 10;//将10 赋值给了e
//扩展赋值运算符: += -= *= /= %=
//+=加等于 左边加上右边,结果赋值给了左边的变量
e+=10;
System.out.println("e:"+e);
e *= 10
System.out.println()
System.out.println()
}
}