官术网_书友最值得收藏!

3.12 Sample Program Practice

Example 3.1

//擴(kuò)展精度
class typetest {
   public static void main (String args[]) {
    long bigInteger = 98765432112345678L;
    float realNo = bigInteger;
    System.out.println(bigInteger);
    System.out.println(realNo);
   }
}

Example 3.2

//顯式轉(zhuǎn)換
class typetest2 {
   public static void main(String args[]) {
       byte b = 0;
       char c = 'A';
       short s = 0;
       int i = 0;
       long l = 0L;
       float f = 0.0F;
       double d = 0.0;
       f = l;
       l = (long)f;
       d = b;
       b = (byte)s;
       s = (short)c;
       c = (char)s;
       b = (byte)c;
       b = (byte)s;
       c = (char)b;
       i = b;
       System.out.print (……what ever you want to print here);
   }
}

Example 3.3

//十六進(jìn)制的轉(zhuǎn)換
public class Tester {
  public static void main(String[] args) {
    short s1 = 0x1234;
    int i1 = 0x0000abcd;
    byte b1;
    b1 = (byte)s1;
    System.out.println("s1=" + s1 + ", b1=" + b1);
    s1 = (short)i1;
    b1 = (byte)s1;
    System.out.println("i1=" + i1 + ", s1=" + s1 + ", b1=" + b1);
  }
}
主站蜘蛛池模板: 玛多县| 唐海县| 宣汉县| 沙河市| 吴江市| 迁西县| 金川县| 磐石市| 金湖县| 云林县| 石景山区| 乌什县| 郸城县| 瑞昌市| 柞水县| 高密市| 龙里县| 金山区| 通城县| 报价| 大邑县| 陈巴尔虎旗| 平远县| 宜兰县| 唐山市| 大安市| 临沭县| 千阳县| 岳西县| 双鸭山市| 江川县| 吉隆县| 长白| 唐山市| 定西市| 泾阳县| 宣武区| 宜阳县| 隆昌县| 德格县| 虞城县|