1.inta=2;System.out.println(a++);System.out.println(a);System.out.println(++a);结果:2342.intx=4;System.out.println(valueis+((x4)?99.99:9));结果:valueis9.03.intx=125;System.out.println(x%2);System.out.println(x/10);System.out.println(x%3==0);结果:112False4.System.out.print(7%-2+\t);System.out.print(7%2+\t);System.out.print(-7%2+\t);System.out.print(-7%-2+\t);System.out.print(7.2%2.8=+7.2%2.8);结果:11-1-17.2%2.8=1.60000000000000055.inta=6,b=7,c=8;doubled=3.14;Stringx=hello;System.out.println(a+b+x+c+d);结果:13hello83.146.chara='6';intd=a-'0';System.out.println(a+1);System.out.println(d+1);结果:5577.Stringc=red;switch(c){default:System.out.println(white);break;casered:System.out.println(red);break;caseblue:System.out.println(blue);break;}结果:red8.outer:for(inti=1;i3;i++){for(intj=1;j4;j++){if(i==1&&j==2)continueouter;System.out.println(i=+i+j=+j);}}结果:i=1j=1i=2j=1i=2j=2i=2j=39.intj=0;do{if(j==5)continue;System.out.print(j+);j++;}while(j10);结果:0123410.inti=10,j=10;booleanb=false;if(b=i==j)System.out.println(True);elseSystem.out.println(False);结果:True11.inta=1,b=2,c=3,d=0;if(a1)if(a2)d=4;elsed=2;elseif(bc)d=3;elsed=1;System.out.println(d=+d);结果:d=112.intm=8,n=5;while(m2){if(mn)m=m-n;elsen=n-m;}System.out.println(m);结果:113.intx=1,y=1,z=1;if(x--==1&&y++==1||z++==1)System.out.println(x=+x+,y=+y+,z=+z);结果:x=0,y=2,z=114.intx=23659;Stringm=resule=;while(x0){m=m+x%10;x=x/10;}System.out.println(m);结果:resule=9563215.inti=0,j=5;top:for(;;){i++;for(;;)if(i--j)breaktop;}System.out.println(i=+i+,j=+j);结果:i=1,j=016.int[]a=newint[6];for(intm=0;ma.length;m++){a[m]=m+1;System.out.print(a[m]);if(m%3==0)System.out.println();}结果:12345617.publicstaticvoidmain(String[]args){ints=f(3)+f(2);System.out.println(s=+s);}publicstaticintf(intk){intm=1,r=1;while(m=k){r=r*m;m++;}returnr;}结果:s=818.publicstaticvoidmain(String[]args){int[]a={1,2,3,4};for(inti=0;i4;i++)a[i]=a[i]+i;for(intb:a)System.out.println(b);}结果:135719.publicstaticvoidmain(String[]args){System.out.println(fun(2));}staticintfun(intx){intj=1;switch(x){case1:j++;case2:j++;case3:j++;default:j++;}returnj+x;}结果:620.publicstaticvoidmain(String[]args){int[]a={3,1,5,4};System.out.println(fun(a,3));}staticintfun(intk[],intn){if(n0)returnn+fun(k,n-1);elsereturn0;}结果:621.classParent{protectedstaticintcount=0;publicParent(){count++;}}publicclassChildextendsParent{publicChild(){count++;}publicstaticvoidmain(String[]args){Childx=newChild();System.out.println(count=+count);}}结果:count=222.publicclassA{protectedvoidtest(floatx){System.out.println(test(float):+x);}protectedvoidtest(Objectobj){System.out.println(test(Object):+obj);}protectedvoidtest(Stringstr){System.out.println(test(String):+str);}publicstaticvoidmain(String[]args){Aa1=newA();a1.test(hello);a1.test(5);}}结果:test(String):hellotest(float):5.023.classexSuper{publicvoidfunc(Stringp,Strings){System.out.println(p);}}publicclassexampleextendsexSuper{publicvoidfunc(Stringp,Strings){System.out.println(p+:+s);}publicstaticvoidmain(String[]args){exSupere1=newexSuper();e1.func(hello1,hi1);exSupere2=newexample();e2.func(hello2,hi2);}}结果:hello1hello2:hi224.classTree{}classPineextendsTree{}classOakextendsTree{}publicclassForest{publicstaticvoidmain(String[]args){Treetree=newPine();if(treeinstanceofPine)System.out.println(Pine);if(treeinstanceofTree)System.out.println(Tree);if(treeinstanceofOak)System.out.println(Oak);elseSystem.out.println(Oops);}}结果:PineTreeOops25.publicclassisEqual{intx;publicisEqual(intx1){x=x1;}publicstaticvoidmain(String[]args){isEqualm1=newisEqual(4);isEqualm2=newisEqual(4);isEqualm3=m2;m3.x=6;System.out.println(m1=m2is+(m1==m2));System.out.println(m2=m3is+(m2==m3));System.out.println(m1.x==m2.xis+(m1.x==m2.x));System.out.println(m1.equals(m2)=+m1.equals(m2));}}结果:m1=m2isfalsem2=m3istruem1.x==m2.xisfalsem1.equals(m2)=false25.abstractclassA{voidm1(){System.out.println(m1());}abstractvoidm2();}interfaceB{voidn();}publicclasstestextendsAimplementsB{voidm2(){System.out.println(callm2());}publicvoidn(){System.out.println(calln());}publicstaticvoidmain(String[]args){testobj=newtest();obj.m1();obj.m2();obj.n();}}结果:m1()callm2()calln()26.publicfinalclasstest{classInner{voidtest(){if(test.this.flag)sample();elseSystem.out.println(innertest);}}privatebooleanflag=false;publicvoidsample(){System.out.println(sample);}publictest(){flag=true;(newInner()).test();}publicstaticvoidmain(String[]args){newtest();}}结果:sample27.interfaceA{floatv=2.0f;voidinit();}classB{intv=3;voidoutput(){System.out.println(v);}}publicclasstestextendsBimplementsA{publicvoidinit(){System.out.println(doinit);}publicstaticvoidmain(String[]args){testx=newtest();x.init();x.output();x.printV();}voidprintV(){System.out.println(super.v+A.v);}}结果:doinit35.027.publicclassEx2{publicstaticvoidmain(String[]args){Stringstr=null;try{if(str.length()==0){System.out.print(The);}System.out.print(Cow);}catch(Exceptione){System.out.print(and);System.exit(0);}finally{System.out.print(Chicken);}System.out.println(show);}}结果:and28.publicclassA{staticintsome(){try{System.out.println