标签:font convert oss float 简化 eval 目标 ssi short
变量要先赋值后使用
计算并赋值运算符
public class CalcAndAssign { public static void main(String[] args) { int a = 16; a >>= 2; System.out.println(a); // 此时a为4 a*=9; System.out.println(a); // 此时a为36 } }
数据类型自动转换
public class AutoConvert { public static void main(String[] args) { int intVal = 99; long longVal = intVal; long longVal2 = intVal + 1; System.out.println(longVal2); float floatVal = 11.32f; double doubleVal = floatVal; double doubleVal2 = doubleVal * 2; System.out.println(doubleVal2); int a = 99; double b = 5; System.out.println(a/b); char ch = ‘A‘; int chNum = ch; int chNumCalc = ch + 10; System.out.println(ch); System.out.println(chNum); System.out.println(chNumCalc); } }
强制数据类型转换
public class ForceConvert { public static void main(String[] args) { int intVal = 99; long longVal = 19999; intVal = (int)longVal; float floatVal = 11.32f; double doubleVal = 3344556.789; floatVal = (float) doubleVal; int A = 65; char b = (char) A; System.out.println(b); } }
public class ForceConvertValueLoss { public static void main(String[] args) { int intVal = 99; long longVal = 5555555555555L; intVal = (int) longVal; System.out.println(intVal); float floatVal = 11.32f; double doubleVal = 1234567890.123456; floatVal = (float) doubleVal; System.out.println(floatVal); System.out.println(doubleVal); } }
数值溢出
public class CalcValueLoss { public static void main(String[] args) { int intVal = 2000000000; System.out.println(intVal + intVal); } }
从数值计算溢出理解程序员和编程语言责任的分界线
标签:font convert oss float 简化 eval 目标 ssi short
原文地址:https://www.cnblogs.com/buildnewhomeland/p/12113428.html