疯狂JAVA讲义第三章之数组篇
package test;
/** * Desription: * @author orangebook *<br/>网站:《a href="http://www.crazyit.org">疯狂Java联盟</a> *<br/> */
public class javadocTest { /** * 简单的测试Field */ protected String name; public static void main(String[] args) { long binVall=16; binVall=binVall>>>2; System.out.println(binVall); System.out.println("hello world"); }
} |
package test; /** * Description: * <br/>网站:<a href="http://www.crazyit.org">疯狂 Java 联盟</a> * <br/>Copyright (c) , 2001-2012,Yeeku.H.Lee * <br/>This program is protected by copyright laws. * <br/>Program Name: * <br/>Date: * @author orangebook * @version 1.0 */ public class Test { /** * 简单测试 Fiedld */ public int age; public Test() {
}
} |
package test; public class javadocTest { protected String name; public static void main(String[] args) { String[] test; test=new String[4]; test[0]="疯狂Java讲义"; test[1]="轻量级Java EE 企业应用实战"; for(int i=0;i<test.length;++i) System.out.println(test[i]); }
} |
package test;
public class javadocTest { public static void main(String[] args) { String[] test; test = new String[4]; test[0] = "疯狂Java讲义"; test[1] = "轻量级Java EE 企业应用实战"; test[2] = "疯狂Android讲义"; for (String book : test) System.out.println(book); } } |
package test;
public class javadocTest { public static void main(String[] args) { int[] a = { 5, 7, 20 }; int[] b = new int[4];
System.out.println("b数组的长度为:" + b.length); for (int i = 0, len = a.length; i < len; ++i) { System.out.println(a[i]); } for (int i = 0, len = b.length; i < len; ++i) { System.out.println(b[i]); } b = a; System.out.println("b数组的长度为:" + b.length); } } |
package test;
public class javadocTest {
public static void main(String[] args) { Person[] students;
students = new Person[2]; Person zhang = new Person(); zhang.age = 15; zhang.height = 158; Person lee = new Person(); lee.age = 16; lee.height = 161; students[0] = zhang; students[1] = lee; lee.info(); students[1].info(); students[0].info(); } }
class Person { public int age; public double height;
public void info() { System.out.println("我的年龄是:" + age + ",我的身高是:" + height); } } |
package test;
public class javadocTest {
public static void main(String[] args) { int[][] a; a = new int[4][]; // 把a当成一维数组,查看每个数组元素的值 for (int i = 0, len = a.length; i < len; ++i) { System.out.println(a[i]); } a[0] = new int[2]; a[0][1] = 6; for (int i = 0, len = a[0].length; i < len; ++i) { System.out.println(a[0][i]); }
} } |
package test;
import java.util.Arrays;
public class javadocTest {
public static void main(String[] args) { int[] a = new int[] { 3, 4, 5, 6 }; int[] a2 = new int[] { 3, 4, 5, 6 }; //用来判断两个数组是否相等 System.out.println("a的数组和a2数组是否相等:" + Arrays.equals(a, a2)); int[] b = Arrays.copyOf(a, 6); System.out.println("a的数组和b数组是否相等:" + Arrays.equals(a, b)); //将一个数组转化为字符串 System.out.println("b数组元素为" + Arrays.toString(b)); Arrays.fill(b, 2, 4, 1); //对数组中的元素排序 Arrays.sort(b); System.out.println("b数组的无线为:" + Arrays.toString(b));
} } |