.Methods public static String toString( public static int parselnt(String s) intj=Integer.parseInt(“123”); public static Integer valueOf(String s) int j Integer.valueOf("123").intValue(); >注:类似double、float数据,没有parseInt方法, 只能用上述步骤将字符串转换成数值数据 float f=Float.valueOf("12.3").floatValue();
7-6 Programming in Java •Methods ¾ public static String toString() ¾ public static int parseInt(String s) int j = Integer.parseInt(“123”); ¾ public static Integer valueOf(String s) int j = Integer.valueOf(“123”).intValue(); ¾注:类似double、float数据,没有parseInt方法, 只能用上述步骤将字符串转换成数值数据 float f = Float.valueOf(“12.3”).floatValue(); Integer类(2)
Matn Mth类包括一系列常量和常用的数学运算方法 所有的操作都是double Math.E代表e(2.7182818284590452354) Math.PI代表元(3.14159265358979323846) 在所有方法中角度都是采用弧度制,所有参数和 返回值都是double 静态方法randome0返回伪随机数r(0.0<=r<1.0) 例如:intj=(int)(Math.random0*10)+l;
7-7 Programming in Java Math 类包括一系列常量和常用的数学运算方法 Math 类 • 所有的操作都是 double • Math.E 代表 e(2.7182818284590452354) Math.PI 代表π(3.14159265358979323846) • 在所有方法中角度都是采用弧度制,所有参数和 返回值都是 double • 静态方法 random()返回伪随机数 r (0.0 <= r < 1.0) • 例如:int j = (int)(Math.random()*10)+1;
7入 标准的I/O Stream 。 public static InputStream in ● public static PrintStream out public static PrintStream err System方法 Public static long currentTime Millis() Public static void exit(int status) Public static void gcO
7-8 Programming in Java 标准的 I/O Stream • public static InputStream in • public static PrintStream out • public static PrintStream err System 方法 • Public static long currentTimeMillis() • Public static void exit(int status) • Public static void gc() System 类
Java 改雅 7 Java语言中数组的特点 >数组中元素是有先后次序的 > 每个数组中元素类型是相同的 >通过索引直接访问元素 > 数组一旦建立大小就固定了
7-9 Programming in Java • Java 语言中数组的特点 ¾ 数组中元素是有先后次序的 ¾ 每个数组中元素类型是相同的 ¾ 通过索引直接访问元素 ¾ 数组一旦建立大小就固定了 Java 数组
下神 String[friends; /声明数组 friends=new String3];/创建数组空间 ∥初始化数组 friends[O]=“Greg”; friends[1]=Sam”; friends[2]=Elmo”;
7-10 Programming in Java 示例 String[ ] friends; //声明数组 friends = new String[3]; //创建数组空间 // 初始化数组 friends[0] = “Greg”; friends[1] = “Sam”; friends[2] = “Elmo”;