zoukankan      html  css  js  c++  java
  • java语言基础--byte、short、char的混合运算

     1 /*
     2       结论:byte、char、short做混合运算的时候,各自先转换成int再做运算。
     3  */
     4 public class IntTest {
     5     public static void main(String[] args) {
     6         
     7         char c1 = 'a';
     8         byte b = 1;
     9         //注意:这里的“+”是负责求和
    10         System.out.println(c1 + b);//输出结果:98
    11         
    12         //错误:不兼容类型:从int转换到short可能会有损失
    13         //Type mismatch: cannot convert from int to short
    14         //short s = c1 + b;//编译器不知道这个加法最后的结果是多少,只知道是int类型
    15         //修改
    16         short  s= (short)(c1 + b);
    17         
    18         short k = 98;//可以实现,直接赋值
    19         
    20         int a = 1;
    21         //错误:不兼容类型:从int转换到short可能会有损失
    22         //Type mismatch: cannot convert from int to short
    23         short x = a;//不可以,编译器只知道a是int类型,不知道a中存储的是哪个值
    24         System.out.println(x);
    25     }
    26 }
  • 相关阅读:
    代码对齐[UVA1593]
    数数字
    子序列
    细菌培养
    内联函数那些事情
    一个简单的问题
    头文件重复包含问题的一点笔记
    mapreduce 对文件分词读取
    hadoop hive-2.3.5安装
    hadoop sqoop 实例
  • 原文地址:https://www.cnblogs.com/llrra/p/14637091.html
Copyright © 2011-2022 走看看