zoukankan      html  css  js  c++  java
  • 基本数据类型的转换

    Java中类型由低到高的顺序为:byte  short  char  int  long  float  double  

    Java中数据类型转换分为4类

    1.基本数据类型自动转换

    当低到高时可以自动转换 如:  byte b; short s=b; char c=b; int i=b; long l=b; float f=b; double d=b;

    2.基本数据类型强制转换

    当高到低时必须强制转换如:double d; float f=(float) d; int i=(int) d;

    3.字符串型数据与其他数据类型转换

    Java中通过toString方法实现

    如:int i=1;

          Integer I= new Integer(i);//生成integer类

          String s=I.toString();//toString方法完成Integer类型转换为字符串

    4.将char型值直接作为数字转换为其他数据类型

    数据类型转换小程序

    package ch01;

    public class Changetest {
    public static void main(String args[]){
    byte b=10;
    short s=b;
    int i=b;
    float f=b;
    double d=b;
    int n=1;
    byte m=(byte) n;
    System.out.println(b);
    System.out.println(s);
    System.out.println(i);
    System.out.println(f);
    System.out.println(d);
    System.out.println(n);
    System.out.println(m);


    }

    }

  • 相关阅读:
    bzoj3293 分金币
    考前模板整理
    CF785D Anton and School
    容斥法解决错排问题
    CF1248F Catowice City
    CF1248E Queue in the Train
    CF1244F Chips
    CF1244C The Football Season
    Noip2016Day1T2 天天爱跑步
    Noip2015Day2T3 运输计划
  • 原文地址:https://www.cnblogs.com/gc56-db/p/6685824.html
Copyright © 2011-2022 走看看