变量定义 public class Main { public static void main(String[] args) { // 定义byte类型的变量 byte b = 10; System.out.println(b); // 定义short类型的变量 short s = 100; System.out.println(s); // 定义int类型的变量 int i = 1000; System.out.println(i); // 定义long类型的变量 long l = 1000…
在java中变量转发分为两种,隐式转换和强制转换 隐式转换: byte a = 10; int b = 20; byte c = a + b; // 该方法会报错,转换过程中字节数只能从小变大,不能从大变小 int d = a + b; // 改方法则正常 System.out.println(c); 强制转换: 建议:数据做运算,结果应该是什么类型,就用什么类型接收,不要随意转换类型,否则会有精度的损失 byte a = 10; int b = 20; // 目标类型 变量名 = (目标类型)…