- 获取整形 最大最小值
Integer.MIN_VALUE
Integer.MAX_VALUE
Math.max() 和 min() : 只有两个参数
https://www.twle.cn/l/yufei/java/java-basic-math-max.html
指数运算:https://blog.csdn.net/weixin_43838265/article/details/120918398
int a2=2;
int e2=3;
double res2=Math.pow(a2,e2); //2的3次方,int会自动向上转型成double
Math.round()方法:对小数进行四舍五入运算,参数只能是float 或 double
https://blog.csdn.net/fenggering/article/details/55806408
Math.abs() 求绝对值
Math.sqrt() : double sqrt = Math.sqrt(9) // 3.0
字符串转整数
String s = "1122";
int i = Integer.parseInt(s);
- 字符和整形互相转换:
char a = '1';
int i = (int)a;
char b = 'b';
int j = (int)b;
System.out.println(i); // 49
System.out.println(j); // 98
char a = '1';
char b = '0';
int i = a - b;
System.out.println(i); // 1
int c = (int)a;
int d = (int)b;
System.out.println(c); // 49
System.out.println(d); // 48
int x = 48;
char q = (char)x;
System.out.println(q); //'0'
网友评论