张孝祥《Java就业培训教程》源代码 02 部分来源: 发布时间:星期一, 2009年11月30日 浏览:0次 评论:0
Java就业培训教程 作者:张孝祥 书中源码
Java就业培训教程P34源码 清单:Promote.java Promote { public void (String args) { b = 50; char c = 'a'; s = 1024; i = 50000; float f = 5.67f; double d = .1234; double result = (f * b) + (i / c) - (d * s); .out.prln((f * b) + " + " + (i / c) + " - " + (d * s)); .out.prln("result = " + result); } } Java就业培训教程P35源码 清单:TestScope.java public TestScope { public void (String args) { x = 12; { q = 96; // x和q都可用 .out.prln("x is "+x); .out.prln("q is "+q); } q = x; /* 行只有x可用 q 超出了作用域范围 */ .out.prln("x is "+x); } } Java就业培训教程P37源码 清单:TestVar.java public TestVar { public void (String args) { x;//应改为 x=0; x=x+1; //这个x由于没有化编译会报错 .out.prln("x is "+x); } } 清单:Func1.java public Func1 { public void (String args) { /* 下面是打印出第个矩形代码*/ for( i=0;i<3;i) { for( j=0;j<5;j) { .out.pr("*"); } .out.prln; //换行 } .out.prln; //下面是打印出第 2个矩形代码 for( i=0;i<2;i) { for( j=0;j<4;j) { .out.pr("*"); } .out.prln; } .out.prln; //下面是打印出第 3个矩形代码 for( i=0;i<6;i) { for( j=0;j<10;j) { .out.pr("*"); } .out.prln; } .out.prln; } } Java就业培训教程P39源码 清单:Func2.java public Func2 { public void drawRectangle( x, y) { for( i=0;i<x;i) { for( j=0;j<y;j) { .out.pr(" * "); } .out.prln; //换行 } .out.prln; } public void (String args) { drawRectangle(3,5); drawRectangle(2,4); drawRectangle(6,10); } } Java就业培训教程P40源码 清单:Func3.java public Func3 { public getArea( x, y) { x*y; } public void (String args) { area = getArea(3,5); .out.prln("first Acreage is " + area); .out.prln("second Acreage is "+ getArea(2,4)); getArea(6,10); } } Java就业培训教程P41源码 清单:Func4.java public Func4 { public getArea( x, y) { (x<=0 || y<=0) { -1; } x*y; } public void (String args) { area = getArea(3,5); .out.prln("first Acreage is " + area); .out.prln("second Acreage is "+ getArea(2,4)); getArea(6,10); } } Java就业培训教程P43源码 清单:Test.java public Test { public void (String args) { isum; double fsum; isum=add(3,5); isum=add(3,5,6); fsum=add(3.2,6.5); } public add( x, y) { reutrn x+y; } public add( x, y, z) { x+y+z; } public double add(double x,double y) { x+y; } } Java就业培训教程P47源码 public TestAnd { public void (String args) { x=0; y=0; (x!=0 && yy/x) .out.prln("y = "+y); } } Java就业培训教程P48源码 清单:ShtTest.java public ShtTest { public void (String args) { x=0x80000000; y=0x80000000; x=x>>1; y=y>>>1; .out.prln("0x80000000>>1 = " + Integer.toHexString(x)); .out.prln("0x80000000>>>1 = " + Integer.toHexString(y)); } } Java就业培训教程P61源码 清单:TestDo.java public TestDo { public void (String args) { x=3; while(x0) { .out.prln("ok1"); x; } y=3; do { .out.prln("ok2"); y; } while(y0); } } Java就业培训教程P64源码 清单:PrOddNum.java public PrOddNum { public void (String args) { for( i=0;i<10;i) { (i%20) continue; .out.prln(i); } } } Java就业培训教程P67源码 清单:TestArray.java public TestArray { public void (String args) { x; x= [100]; for( i=0;i<100;i) { .out.prln("x"+i+" is "+x[i]); } } } Java就业培训教程P73源码 清单:TestArrayCopy.java public TestArrayCopy { public void (String args) { ia= {1,2,3,4,5}; ib= {9,8,7,6,5,4,3}; ..gif' />copy(ia,0,ib,0,3); // 复制源中从下标0开始3个元素到目从下标0位置开始存储 for( i=0;i<ia.length;i) .out.pr(ia[i]); .out.prln; for( j=0;j<ib.length;j) .out.pr(ib[j]); .out.prln; } } 0
相关文章读者评论发表评论 |