一:字符串操作符 “+”、“+=”
对于“+”的使用,当所有值都是数字的时候,执行计算处理;当有一个是字符类型的时候,就将数字转换为String字符串进行拼接处理。
二:类型转换操作符
public class Text {
public static void main(String[] args) {
double above = 0.7, below = 0.4;
float fabove = 0.7f, fbelow = 0.4f;
System.out.println("(int)above:0.7 - " + (int)above + "\nMath.round(above):0.7 - " + Math.round(above));
System.out.println("(int)below:0.4 - " + (int)below + "\nMath.round(below):0.4 - " + Math.round(below));
System.out.println("(int)fabove:0.7f - " + (int)fabove + "\nMath.round(fabove):0.7f - " + Math.round(fabove));
System.out.println("(int)fbelow:0.4f - " + (int)fbelow + "\nMath.round(fbelow):0.4f - " + Math.round(fbelow));
}
}
结果:
(int)above:0.7 - 0
Math.round(above):0.7 - 1
(int)below:0.4 - 0
Math.round(below):0.4 - 0
(int)fabove:0.7f - 0
Math.round(fabove):0.7f - 1
(int)fbelow:0.4f - 0
Math.round(fbelow):0.4f - 0
知识点:
double 或者 float 类型转换为 int 类型,都是进行截取掉小数点之后得到的结果,而round()方法是进行四舍五入的操作。