zoukankan      html  css  js  c++  java
  • java语言基础--多种数据类型混合运算

     1 /*
     2       结论:多种数据类型做混合运算的时候,最终的结果类型是“最大容量”对应的类型。
     3       
     4       char+short+short除外
     5       因为char+short+short做混合运算的时候,会各自先转换成int再做运算
     6  */
     7 public class IntTest {
     8     public static void main(String[] args) {
     9         
    10         long a = 10L;
    11         char c = 'a';
    12         short s = 100;
    13         int i =30;
    14         System.out.println(a+c+s+i);
    15         
    16         //错误:不兼容类型:从long类型转换到int可能会有损失
    17         //Type mismatch: cannot convert from long to int
    18         //int x = a + c + s + i;
    19         //修改
    20         int x = (int)(a+c+s+i);
    21         System.out.println(x);
    22         
    23         //以下程序执行结果是?
    24         //Java中规定int类型和int类型最终结果还是int类型
    25         int temp = 10/3;//最终取整
    26         System.out.println(temp);//结果:3
    27         
    28         
    29         //在java中计算结果不一定是精确的
    30         int temp2 = 1/2;
    31         System.out.println(temp2);//结果:0
    32     }
    33 }
  • 相关阅读:
    数据库默认隔离级别
    openldap安装
    new word
    ldap概念
    Oracle 计算函数
    informix 学习资料收集
    convert to groovy project
    ldap资料
    hibernate session
    IE BUG相关文章集合
  • 原文地址:https://www.cnblogs.com/llrra/p/14637150.html
Copyright © 2011-2022 走看看