Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update

  • Loading branch information...
commit 98c3f5a0a6a785032fbdd6e4ebfe34d416c7379f 1 parent a783ae6
@astrotycoon authored
View
BIN  array/Arr/Arr.class
Binary file not shown
View
36 array/Arr/Arr.java
@@ -0,0 +1,36 @@
+public class Arr {
+ public static void main(String args[]) {
+ int a[] = {1, 2, 3, 4};
+ int b[] = {100, 200, 300};
+ int c[] = {7, 8, 9};
+ char d[] = {'A', '', '', '', '!'};
+
+ System.out.println("数组a的元素个数 = "+ a.length);
+ System.out.println("数组b的元素个数 = "+ b.length);
+ System.out.println("数组c的元素个数 = "+ c.length);
+
+ System.out.println("数组a的引用 = "+ a);
+ System.out.println("数组b的引用 = "+ b);
+ System.out.println("数组cde引用 = "+ c);
+
+ System.out.println("a == b的结果是"+ (a == b));
+ a = b;
+ System.out.println("数组a的元素个数 = "+ a.length);
+ System.out.println("数组b的元素个数 = "+ b.length);
+
+ System.out.println("a == b的结果是"+ (a == b));
+ System.out.println("a[0] ="+ a[0] + ",a[1] ="+ a[1]+ ",a[2] ="+ a[2]);
+ System.out.println("b[0] ="+ b[0] + ",b[1] ="+ b[1] +",b[2] ="+ b[2]);
+
+ System.out.println("b == c的结果是"+ (b == c));
+ b = c;
+ System.out.println("数组b的元素个数 = "+ b.length);
+ System.out.println("数组c的元素个数 = "+ c.length);
+ System.out.println("b[0] = "+ b[0] +",b[1] = "+ b[1] +",b[2] = "+ b[2]);
+ System.out.println("c[0] = "+ c[0] +",c[1] = "+ c[1] +",c[2] = "+ c[2]);
+
+ System.out.println(d);
+ System.out.println("数组d的引用"+a);
+ System.out.println("数组d的元素个数 = "+ d.length);
+ }
+}
View
BIN  array/array_copy/array_copy.class
Binary file not shown
View
24 array/array_copy/array_copy.java
@@ -0,0 +1,24 @@
+import java.util.Arrays;
+public class array_copy {
+ public static void main(String args[]) {
+ char [] a = {'a', 'b', 'c', 'd', 'e', 'f'},
+ b = {'1', '2', '3', '4', '5', '6'};
+ int [] c = {1, 2, 3, 4, 5, 6},
+ d = {10, 20, 30, 40, 50, 60};
+
+ System.arraycopy(a, 0, b, 0, a.length);
+ System.arraycopy(c, 2, d, 2, c.length - 3);
+
+ System.out.println("数组a的各个元素中的值:");
+ System.out.println(Arrays.toString(a));
+
+ System.out.println("数组b的各个元素中的值:");
+ System.out.println(Arrays.toString(b));
+
+ System.out.println("数组c的各个元素中的值:");
+ System.out.println(Arrays.toString(c));
+
+ System.out.println("数组d的各个元素中的值:");
+ System.out.println(Arrays.toString(d));
+ }
+}
View
BIN  array/copy_of/copy_of.class
Binary file not shown
View
24 array/copy_of/copy_of.java
@@ -0,0 +1,24 @@
+import java.util.*;
+public class copy_of {
+ public static void main(String args[]) {
+ int [] a = {10, 20, 30, 40, 50, 60}, b, c, d;
+
+ b = Arrays.copyOf(a, 10);
+ System.out.println("数组a的各个元素中的值:");
+ System.out.println(Arrays.toString(a));
+
+ System.out.println("数组b的各个元素中的值:");
+ System.out.println(Arrays.toString(b));
+ System.out.println("数组b元素个数 = "+ b.length);
+
+ c = Arrays.copyOfRange(a, 3, 5);
+ System.out.println("数组c的各个元素中的值:");
+ System.out.println(Arrays.toString(c));
+ System.out.println("数组c元素个数 = "+ c.length);
+
+ d = Arrays.copyOfRange(a, 3, 9);
+ System.out.println("数组d的各个元素中的值:");
+ System.out.println(Arrays.toString(d));
+ System.out.println("数组d元素个数 = "+ d.length);
+ }
+}
View
BIN  array/sort_binarysearch/sort_binarysearch.class
Binary file not shown
View
16 array/sort_binarysearch/sort_binarysearch.java
@@ -0,0 +1,16 @@
+import java.util.*;
+public class sort_binarysearch {
+ public static void main(String args[]) {
+ int [] a = {12, 34, 9, 23, 45, 6, 45, 90, 123, 19, 34};
+
+ Arrays.sort(a);
+ System.out.println(Arrays.toString(a));
+ int number = 45;
+ int index = Arrays.binarySearch(a, number);
+ if (index >= 0) {
+ System.out.println(number +"和数组中索引为"+ index +"的元素值相同");
+ } else {
+ System.out.println(number +"不与数组中任何元素值相同");
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.