zoukankan      html  css  js  c++  java
  • 类型转换代码

    public class J {
    @SuppressWarnings("unused")
    public static void main(String[] args) {
    int i = 786;
    byte b = (byte) i;
    short s = (short) i;
    System.out.println(b);
    System.out.println(s);

    int x = (int)3.6;
    System.out.println(x);

    //自动转换 赋值运算
    long l = 7;//7默认为整型 int->long
    int i1 = 5;
    int i2 = 6;
    char c = 'A';
    System.out.println(l+i1+i2+c);
    //强制类型转换
    int i3 = (int)7l;//long-->int

    int i4 = 5;
    int j = 0;
    int result1 = i4++ +j;//result=i4+j i4=i4+1 i4=6
    int result2 = ++i4 +j;//i4=i4+1 result=i4+j
    System.out.println(result1);
    System.out.println(result2);
    int j1 = 6;
    int i5 = 4;
    System.out.println(i5*=j1+4);
    //多目运算符(三目运算符)
    int mm;
    System.out.println(5>7?mm=3:(mm=2));

    int left=10;
    int right=8;
    int mid;
    System.out.println("左手的牌是:"+left);
    System.out.println("右手的牌是:"+right);
    System.out.println("开始交换手里的牌");
    mid = left;
    left = right;
    right = mid;
    System.out.println("左手的牌是:"+left);
    System.out.println("右手的牌是:"+right);



    }
    }

  • 相关阅读:
    接口测试基础07
    性能测试基础01
    接口测试基础06
    将java list转换为js的数组
    java 网络编程
    java分页
    单例模式
    适配器模式
    抽象工厂模式
    工厂模式
  • 原文地址:https://www.cnblogs.com/zaoxi11/p/6026282.html
Copyright © 2011-2022 走看看