2013年2月14日
摘要: 1 package chapter8对象和类; 2 3 public class Circle2 { 4 double radius; 5 static int numberOfObjects = 0; 6 7 Circle2() { 8 radius = 1.0; 9 numberOfObjects++;10 }11 12 Circle2(double newRadius) {13 radius = newRadius;14 numberOfObjects++;15 }16 ... 阅读全文
posted @ 2013-02-14 21:56 bailun 阅读(865) 评论(0) 推荐(0) 编辑
摘要: Chapter 7 Multidimensional Arrays1 int[][] m = new int[4][5];2 二维数组可以有不同的长度。3 array[0][1] is 2.4.int[][] r = new int[2]; Answer: Invalidint[] x = new int[]; Answer: Invalidint[][] y = new int[3][]; Answer: Valid5. 因为我们需要排序list,排序list将改变list中的内容,唤起is1To9(grid[i])后grid数组中的内容也将改变。Grid中的内容将会改变,因此我们不能使用. 阅读全文
posted @ 2013-02-14 21:44 bailun 阅读(815) 评论(0) 推荐(0) 编辑
摘要: Chapter 9 Strings and Text I/O 1.s1 == s2 => trues2 == s3 => falses1.equals(s2) => trues2.equals(s3) => trues1.compareTo(s2) => 0s2.compareTo(s3) => 0s1 == s4 => trues1.charAt(0) => Ws1.indexOf('j') => -1s1.indexOf("to") => 8s1.lastIndexOf('a') 阅读全文
posted @ 2013-02-14 21:43 bailun 阅读(2794) 评论(0) 推荐(0) 编辑
摘要: Chapter 8 Objects and Classes1. See the section "Declaring and Creating Objects."2. 构造方法是在创建一个对象使用new操作符时调用的。 构造方法没有返回类型,甚至连void也没有。数组是一个对象。 The default value for the elements of an array is 0 for numeric, false for boolean, ‘\u0000’ for char, null for object element type.(a) There is such 阅读全文
posted @ 2013-02-14 21:39 bailun 阅读(3390) 评论(0) 推荐(0) 编辑
  2013年2月3日
摘要: 1 package 编程练习题chapter6; 2 import java.util.Scanner; 3 public class Exercise6_01Extra { 4 public static void main(String[] args){ 5 Scanner input = new Scanner(System.in); 6 boolean[] isCovered = new boolean[99]; 7 8 int number = input.nextInt(); 9 while... 阅读全文
posted @ 2013-02-03 20:31 bailun 阅读(3748) 评论(0) 推荐(0) 编辑
摘要: 1 package 编程练习题chapter5; 2 import java.util.*; //我改了; 3 public class Exercise5_1 { 4 public static void main (String args[]) { 5 Scanner input = new Scanner(System.in); 6 7 System.out.print("Enter a number: "); 8 int number = input.nextInt(); 9 10 ... 阅读全文
posted @ 2013-02-03 20:26 bailun 阅读(3845) 评论(3) 推荐(0) 编辑
摘要: Chapter6Single-dimensionalArrays3声明数组时不分配内存。创建数组时分配内存。xis60Thesizeofnumbersis304.1. 数组中每个元素都有相同的类型。Answer:True2. 一旦数组被声明,大小不能改变。 Answer:False3. 一旦数组被创建,大小不能改变。Answer:True4. 数组中的元素必须是基本数据类型。Answer:False5. Whichofthefollowingstatementsarevalidarraydeclarations?inti=newint(30);Answer:Invaliddoubled[]=n 阅读全文
posted @ 2013-02-03 20:20 bailun 阅读(1278) 评论(0) 推荐(0) 编辑
摘要: Chapter5Methods1.Atleastthreebenefits:(1)Reusecode;(2)Reducecomplexity;(3)Easytomaintain.SeetheSections5.2and5.3onhowtodeclareandinvokemethods.Whatisthesubtledifferencebetween“definingamethod”and“declaringavariable”?Adeclarationusuallyinvolvesallocatingmemorytostoreavariable,butadefinitiondoesn’t.2. 阅读全文
posted @ 2013-02-03 20:19 bailun 阅读(1210) 评论(0) 推荐(0) 编辑
摘要: 1 package chapter7; 2 3 public class PassTwoDimensionalArray { 4 public static void main (String[] args) { 5 java.util.Scanner input = new java.util.Scanner(System.in); 6 7 int[][] m = new int[3][4]; 8 System.out.println("Enter " + m.length + " rows and " + 9 ... 阅读全文
posted @ 2013-02-03 20:18 bailun 阅读(1907) 评论(0) 推荐(0) 编辑
摘要: 1 package chapter6一维数组; 2 3 public class Arrays类 { 4 public static void main(String[] args){ 5 6 double[] numbers = {6.0, 4.4, 1.9, 2.9, 3.4, 3.5}; 7 java.util.Arrays.sort(numbers); 8 9 int[] list = {2, 4, 7, 10};10 System.out.println(java.util... 阅读全文
posted @ 2013-02-03 20:16 bailun 阅读(1227) 评论(0) 推荐(0) 编辑