package test; import java.applet.*; public class test1 extends Thread { static int i; public void run() { System.out.println("run"); } public test1() { } public test1(int x) { } public test1(int x,int y) { //调用本类的其他构造方法 this(x); this(); } public static void f0() { // 测试线程的运行时间 System.out.println("start"); test1 t = new test1(); t.start(); System.out.println("end"); // 结论:先输出本函数的信息,再输出线程的run方法内的信息 } public static void main(String[] args) { f19(); } public static void f19() { // 简述逻辑操作(&,|,^)与条件操作(&&,||)的区别 System.out.println(4&3); System.out.println(4^3); System.out.println(4|3); System.out.println(false|true); System.out.println(false || false); System.out.println(false && false); } public static void f18() { for(int i=0;i<10;i++) System.out.println((byte)(Math.random()*10)); //random函数返回一个【0,1)的double类型数 } public static void f17() { int a = 100, b = 20, c; char oper = '+'; switch (oper) { case '+': c = a + b; break; case '-': c = a - b; break; default: c = a * b; break; } System.out.println(c); } public static void f16() { try { int x[] = new int[-4];//数组可以长度为0,但是不能为负数,如果为1.2,会报语法错误 System.out.println("此行将无法被执行!"); } catch (Exception e) { e.printStackTrace(); System.out.println("exception: " + e.getMessage()); } } public static void f15() { int sum = 0; int ko[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; for (int n = 0; n < 3; n++) for (int m = 0; m < 3; m++) sum += ko[n][m]; System.out.println("sum=" + sum); } public static void f14() { int x = 1, sum = 0; while (x <= 10) { sum += x; x++; } System.out.println("sum=" + sum); } public static void f13() { System.out.println(4 | 3); // 位置或操作符:4:100,3:011,4|3=111=7 } public static void f12() { int index = 1; int[] foo = new int[3];// 初始化为0 int bar = foo[index]; int baz = bar + index; System.out.println(baz); } public static void f11() { // The local variable s may not have been initialized String s; System.out.println("s=" + s); } public static void f1() { // 测试byte类型的取值范围 byte b = 1, c = 1; for (int i = 0; i < 300; i++) { System.out.print(b--); System.out.print(":"); System.out.println(c++); } // 结论 -128->127 } public static void f2() { int i = 1; switch (i) { case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); default: System.out.println("default"); } } public static void f3() { Stu s = new Stu("Allen", (byte) 23); System.out.println(s.toString()); } public static void f4() { // 在定义数组的时候,自动初始化为0,0.0,false int a[] = new int[7]; for (int i = 0; i < a.length; i++) System.out.println(a[i]); byte b[] = new byte[7]; for (int i = 0; i < b.length; i++) System.out.println(b[i]); float f[] = new float[7]; for (int i = 0; i < f.length; i++) System.out.println(f[i]); boolean c[] = new boolean[7]; for (int i = 0; i < c.length; i++) System.out.println(c[i]); double d[] = new double[7]; for (int i = 0; i < d.length; i++) System.out.println(d[i]); } public static void f5() { int I, j, k; I = 100; while (I > 0) { j = I * 2; System.out.println(" The value of j is " + j); k = k + 1;// 变量在使用之前,必须初始化 I--; } } public void f6(int a) { } public void f6(long a) { } public static void f7() { // 测试数学函数 System.out.println("下取整"); System.out.println("Math.floor(-4.7)=" + Math.floor(-4.7));// 下取整 System.out.println("Math.floor(4.7)=" + Math.floor(4.7));// 下取整 System.out.println("近取整"); System.out.println("Math.round(-4.7)=" + Math.round(-4.7));// 近取整 System.out.println("Math.round(-4.7)=" + Math.round(4.7));// 近取整 System.out.println("上取整"); System.out.println("Math.ceil(-4.7)=" + Math.ceil(-4.7));// 上取整 System.out.println("Math.ceil(4.7)=" + Math.ceil(4.7));// 上取整 System.out.println("取大、取小"); System.out.println("Math.min(2, 2)=" + Math.min(2, 2));// 取小 System.out.println("Math.max(4,7)=" + Math.max(4, 7));// 取大 } public void f8() { // 测试i++,++i int x, a = 2, b = 3, c = 4; x = ++a + b++ + c++; System.out.println("a=" + (++a)); System.out.println("b=" + b); System.out.println("c=" + c); System.out.println("x=" + x); int x1 = 1, x2 = 1; System.out.println(x1++); System.out.println(x1); System.out.println(++x1); } public void f9() { //测试标示符定义合法性 int 2variable; int variable2; int _whatavariable; int _3_; int $another,!asd,@asd,#asdf,$sdf,%sdf,^sdf,&aaa; } public void f10() { //测试基本数据类型的赋值 double d1=1.2; double d2=1.2D; double d3=1.3d; float f1=1.2;//error float f2=1.2F; float f3=1.2f; float f4=(float)1.2; long l1=1; long l2=1L; long l3=1l; long l4=0xFF; byte b1=12; byte b2=12B;//error byte b3=12b;//error byte b4=(byte)12; } }