1、Java 就业培训教程P34 的 Java原代码程序清单:Promote.javaclass Promote public static void main(String args) byte b = 50;char c = a;short s = 1024;int i = 50000;float f = 5.67f;double d = .1234;double result = (f * b) + (i / c) - (d * s);System.out.println(f * b) + “ + “ + (i / c) + “ - “ + (d * s);System.out.printl
2、n(“result = “ + result);Java 就业培训教程P35 的 Java原代码程序清单:TestScope.javapublic class TestScopepublic static void main(String args)int x = 12; int q = 96; / x和 q都可用System.out.println(“x is “+x); System.out.println(“q is “+q);q = x; /* 错误的行,只有 x可用, q 超出了作用域范围 */System.out.println(“x is “+x); Java 就业培训教程P37
3、 的 Java原代码程序清单:TestVar.javapublic class TestVarpublic static void main(String args)int x;/应改为 int x=0;x=x+1; /这个 x由于没有初始化,编译会报错。System.out.println(“x is “+x);P38的 Java原代码程序清单:Func1.javapublic class Func1public static void main(String args)/* 下面是打印出第一个矩形的程序代码*/for(int i=0;i1;y=y1;System.out.println(“
4、0x800000001 = “ + Integer.toHexString(x);System.out.println(“0x800000001 = “ + Integer.toHexString(y);Java 就业培训教程P61 的 Java原代码程序清单:TestDo.javapublic class TestDopublic static void main(String args)int x=3;while(x=0)System.out.println(“ok1“);x+;int y=3;doSystem.out.println(“ok2“);y+;while(y=0);Java 就
5、业培训教程P64 的 Java原代码程序清单:PrintOddNum.javapublic class PrintOddNumpublic static void main(String args)for(int i=0;i130)return;age = i; public int getAge() return age;public class TestPersonpublic static void main(String args)Person p1 = new Person();p1.setAge(3);p1.setAge(-6);System.out.println(p1.getA
6、ge();Java 就业培训教程P88 的 Java原代码class Personpublic Person()System.out.println(“the constructor 1 is calling!“);private int age = 10;public void shout()System.out.println(“age is “+age); class TestPersonpublic static void main(String args)Person p1=new Person();p1.shout();Person p2=new Person();p2.shout
7、();Person p3=new Person();p3.shout();Java 就业培训教程P90 的 Java原代码class Personprivate String name=“unknown“;private int age = -1;public Person()System.out.println(“constructor1 is calling“);public Person(String n)name = n;System.out.println(“constructor2 is calling“);System.out.println(“name is “+name);p
8、ublic Person(String n,int a)name = n;age = a;System.out.println(“constructor3 is calling“);System.out.println(“name and age is “+name+“;“+age);public void shout()System.out.println(“listen to me!“); class TestPersonpublic static void main(String args)Person p1=new Person();P1.shout();Person p2=new P
9、erson(“Jack“);P2.shout();Person p3=new Person(“Tom“,18);P3.shout();Java 就业培训教程P94 的 Java原代码class Personprivate Person()System.out.println(“the constructor 1 is calling!“);class TestPersonpublic static void main(String args)Person p1=new Person();Java 就业培训教程P95 的 Java原代码class AString name;public A(String x)name = x; public void func1()System.out.println(“func1 of “ + name +“ is calling“);public void func2()A a2 = new A(“a2“);a2.func1();class TestApublic static void main(String args)A a1 = new A(“a1“);a1.func2();Java 就业培训教程P96 的 Java原代码class AString name;