上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
3.12 Sample Program Practice
Example 3.1
//扩展精度 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
//显式转换 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
//十六进制的转换 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); } }