目标类型 变量名 = (目标类型)(被转换的数据);

 1 public class TypeDemo {
 2   public static viod main(String[] args) {
 3           int a = 10;
 4           byte b = 20;
 5           int c = a + b;    //往大的类型直接转换为隐式转换,不会报错
 6           System.out.println(c);
 7 
 8            byte d = (byte)(a + b);   //强制转换 目标类型加括号    
 9            System.out.println(d);
10     }
11 }

 

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2021-11-18
  • 2021-11-18
  • 2021-09-04
  • 2022-01-09
  • 2021-06-29
  • 2021-12-23
猜你喜欢
  • 2021-11-12
  • 2021-10-02
相关资源
相似解决方案