public class Testfun { public static void main(String[] args) { // (一)跨Number父类的类型转换 // 1、str转int => Integer.parseInt(s1) String s1 = "19"; int i2 = Integer.parseInt(s1);// 数字str转化为对标的int System.out.println("++i2=" + (++i2)); // 2、int转str => Integer.toString(i3) int i3 = 27; String s4 = Integer.toString(i3); System.out.println("s4=" + s4); // 3、浮点转int => (int) d5 double d5 = 21.6; int i6 = (int) d5; System.out.println("i6=" + i6); // 4、int转浮点 => (double) i7 int i7 = 60; double d8 = (double) i7; System.out.println("d8=" + d8); // (二)同Number父类的类型转换 System.out.println(); Integer i9 = new Integer("17"); System.out.println(i9.intValue()); // 数字str转为int => i9.intValue() System.out.println(i9.shortValue());// 数字str转为short => i9.shortValue() System.out.println(i9.byteValue());// 数字str转为byte => i9.byteValue() System.out.println(); // int转str(不同进制形式的str) System.out.println(Integer.toString(456)); //获取10进制str System.out.println(Integer.toBinaryString(456)); //获取2进制str System.out.println(Integer.toHexString(456)); //获取16进制str System.out.println(Integer.toOctalString(456)); //获取8进制str } }