Java 2实用教程(第三版)清华大学出版社(编著耿祥义张跃平)例子源代码建议使用文档结构图(选择Word菜单→视图→文档结构图)第一章Java 语言入门例子1public class Hello{public static void main (String args[ ]){System.out.println("你好,很高兴学习Java");}}例子2public class People{ int height;String ear;void speak(String s){ System.out.println(s);}}class A{ public static void main(String args[]){ People zhubajie;zhubajie=new People();zhubajie.height=170;zhubajie.ear="两只大耳朵";System.out.println("身高:"+zhubajie.height);System.out.println(zhubajie.ear);zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");}}例子3import java.applet.*;import java.awt.*;public class Boy extends Applet{ public void paint(Graphics g){ g.setColor(Color.red);g.drawString("我一边喝着咖啡,一边学Java呢",5,30);g.setColor(Color.blue);g.drawString("我学得很认真",10,50); }}第二章标识符、关键字和数据类型例子1public class Example2_1{ public static void main (String args[ ]){ char chinaWord='你',japanWord='ぁ';int p1=36328,p2=38358;System.out.println("汉字\'你\'在unicode表中的顺序位置:"+(int)chinaWord);System.out.println("日语\'ぁ\'在unicode表中的顺序位置:"+(int)japanWord);System.out.println("unicode表中第20328位置上的字符是:"+(char)p1);System.out.println("unicode表中第12358位置上的字符是:"+(char)p2);}}例子2public class Example2_2{ public static void main (String args[ ]){ int c=2200;long d=8000;float f;图2.2 基本数据的转换与输出 double g=123456789.123456789;c=(int)d;f=(float)g; //导致精度的损失.System.out.print("c= "+c);System.out.println(" d= "+d);System.out.println("f= "+f);System.out.println("g= "+g);}}例子3public class Example2_3{ public static void main(String args[]){ int a[]={100,200,300};int b[]={10,11,12,13,14,15,16};b=a;b[0]=123456;System.out.println("数组a:"+a[0]+","+a[1]+","+a[2]);System.out.println("数组b:"+b[0]+","+b[1]+","+b[2]); System.out.println("数组b的长度:"+b.length);}}第三章运算符、表达式和语句例子1class Example3_1{ public static void main(String args[]){ char a1='十',a2='点',a3='进',a4='攻';char secret='8';a1=(char)(a1^secret);a2=(char)(a2^secret);a3=(char)(a3^secret);a4=(char)(a4^secret);System.out.println("密文:"+a1+a2+a3+a4);a1=(char)(a1^secret);a2=(char)(a2^secret);a3=(char)(a3^secret);a4=(char)(a4^secret);System.out.println("原文:"+a1+a2+a3+a4);}}例子2class Example3_2{ public static void main(String args[]){ int x,y=10;if(((x=0)==0)||((y=20)==20)){ System.out.println("现在y的值是:"+y);}int a,b=10;if(((a=0)==0)|((b=20)==20)){ System.out.println("现在b的值是:"+b);}}}例子3public class Example3_3{ public static void main(String args[]){ int a=9,b=5,c=7,t;if(a>b){ t=a; a=b; b=t;}if(a>c){ t=a; a=c; c=t;}if(b>c){ t=b; b=c; c=t;}System.out.println("a="+a+",b="+b+",c="+c);}}例子4public class Example3_4{ public static void main(String args[]) { int math=65 ,english=85;if(math>60){ System.out.println("数学及格了");}else{ System.out.println("数学不及格");}if(english>90){ System.out.println("英语是优");}else{ System.out.println("英语不是优");}System.out.println("我在学习控制语句");}}例子5public class Example3_5{ public static void main(String args[]) { int x=2,y=1;switch(x+y){ case 1 :System.out.println(x+y);break;case 3:System.out.println(x+y);case 0:System.out.println(x+y);break;default: System.out.println("没有般配的"+(x+y));}}}例子6public class Example3_6{ public static void main(String args[]){ long sum=0,a=5,item=a,n=10,i=1;for(i=1;i<=n;i++){ sum=sum+item;item=item*10+a;}System.out.println(sum);}}例子7class Example3_7{ public static void main(String args[]){ double sum=0,a=1;int i=1;while(i<=20){ sum=sum+a;i=i+1;a=a*(1.0/i);}System.out.println("sum="+sum);}}例子8class Example3_8{ public static void main(String args[]){ int sum=0,i,j;for( i=1;i<=10;i++){ if(i%2==0) //计算1+3+5+7+9 continue;sum=sum+i;}System.out.println("sum="+sum);for(j=2;j<=50;j++) //求50以内的素数{ for( i=2;i<=j/2;i++){ if(j%i==0)break;}if(i>j/2){ System.out.println(""+j+"是素数"); }}}}第四章类、对象和接口例子1class XiyoujiRenwu{ float height,weight;String head, ear,hand,foot, mouth;void speak(String s){ System.out.println(s);}}class A{ public static void main(String args[]){ XiyoujiRenwu zhubajie; //声明对象zhubajie=new XiyoujiRenwu(); //为对象分配内存,使用new 运算符和默认的构造方法 }}例子2class Point{ int x,y;Point(int a,int b){ x=a;y=b;}}public class A{ public static void main(String args[]){ Point p1,p2; //声明对象p1和p2p1=new Point(10,10); //为对象分配内存,使用 new 和类中的构造方法p2=new Point(23,35); //为对象分配内存,使用 new 和类中的构造方法}}例子3class XiyoujiRenwu{ float height,weight;String head, ear,hand,foot,mouth;void speak(String s){ head="歪着头";System.out.println(s);}}class Example4_3{ public static void main(String args[]){ XiyoujiRenwu zhubajie,sunwukong;//声明对象zhubajie=new XiyoujiRenwu(); //为对象分配内存sunwukong=new XiyoujiRenwu();zhubajie.height=1.80f; //对象给自己的变量赋值zhubajie.head="大头";zhubajie.ear="一双大耳朵";sunwukong.height=1.62f; //对象给自己的变量赋值sunwukong.weight=1000f;sunwukong.head="绣发飘飘";System.out.println("zhubajie的身高:"+zhubajie.height);System.out.println("zhubajie的头:"+zhubajie.head);System.out.println("sunwukong的重量:"+sunwukong.weight);System.out.println("sunwukong的头:"+sunwukong.head);zhubajie.speak("俺老猪我想娶媳妇"); //对象调用方法System.out.println("zhubajie现在的头:"+zhubajie.head);sunwukong.speak("老孙我重1000斤,我想骗八戒背我"); //对象调用方法 System.out.println("sunwukong现在的头:"+sunwukong.head);}}例子4class 梯形{ float 上底,下底,高,面积;梯形(float x,float y,float h){ 上底=x;下底=y;高=h;}float 计算面积(){ 面积=(上底+下底)*高/2.0f;return 面积;}void 修改高(float height){ 高=height;}float 获取高(){ return 高;}}public class Example4_4{ public static void main(String args[]){ 梯形 laderOne=new 梯形(12.0f,3.5f,50),laderTwo=new 梯形(2.67f,3.0f,10);System.out.println("laderOne的高是:"+laderOne.获取高());System.out.println("laderTwo的高是:"+laderTwo.获取高());System.out.println("laderOne的面积是:"+laderOne.计算面积());System.out.println("laderTwo的面积是:"+laderTwo.计算面积());laderOne.修改高(10);float h=laderOne.获取高();laderTwo.修改高(h*2);System.out.println("laderOne现在的高是:"+laderOne.获取高());System.out.println("laderTwo现在的高是:"+laderTwo.获取高());System.out.println("laderOne现在的面积是:"+laderOne.计算面积());System.out.println("laderTwo现在的面积是:"+laderTwo.计算面积());}}例子5class People{ String face;void setFace(String s){ face=s;}}class A{ void f(int x,double y,People p){ x=x+1;y=y+1;p.setFace("笑脸");System.out.println("参数x和y的值分别是:"+x+","+y);System.out.println("参数对象p的face是:"+p.face);}}public class Example4_5{ public static void main(String args[]){ int x=100;double y=100.88;People zhang=new People();zhang.setFace("很严肃的样子");A a=new A();a.f(x,y,zhang);System.out.println("main方法中x和y的值仍然分别是:"+x+","+y);System.out.println("main方法中对象zhang的face是:"+zhang.face);}}例子6class 圆{ double 半径;圆(double r){ 半径=r;}double 计算面积(){ return 3.14*半径*半径;}void 修改半径(double 新半径){ 半径=新半径;}double 获取半径(){ return 半径;}}class 圆锥{ 圆底圆;double 高;圆锥(圆 circle,double h){ this.底圆=circle;this.高=h;}double 计算体积(){ double volume;volume=底圆.计算面积()*高/3.0;return volume;}void 修改底圆半径(double r){ 底圆.修改半径(r);}double 获取底圆半径(){ return 底圆.获取半径();}}class Example4_6{ public static void main(String args[]){ 圆 circle=new 圆(10);圆锥 circular=new 圆锥(circle,20);System.out.println("圆锥底圆半径:"+circular.获取底圆半径());System.out.println("圆锥的体积:"+circular.计算体积());circular.修改底圆半径(100);System.out.println("圆锥底圆半径:"+circular.获取底圆半径());System.out.println("圆锥的体积:"+circular.计算体积());}}例子7class 梯形{ float 上底,高;static float 下底;梯形(float x,float y,float h){ 上底=x; 下底=y; 高=h;}float 获取下底(){ return 下底;}void 修改下底(float b){ 下底=b;}}class Example4_7{ public static void main(String args[]){ 梯形 laderOne=new 梯形(3.0f,10.0f,20),laderTwo=new 梯形(2.0f,3.0f,10);梯形.下底=200; //通过类名操作类变量System.out.println("laderOne的下底:"+laderOne.获取下底());System.out.println("laderTwo的下底:"+laderTwo.获取下底());laderTwo.修改下底(60); //通过对象操作类变量System.out.println("laderOne的下底:"+laderOne.获取下底());System.out.println("laderTwo的下底:"+laderTwo.获取下底());}}例子8class Fibi{ public static long fibinacii(int n){ long c=0;if(n==1||n==2)c=1;elsec=fibinacii(n-1)+fibinacii(n-2);return c;}}public class Example4_8{ public static void main(String args[]){ System.out.println(Fibi.fibinacii(7));}}例子9package tom.jiafei;public class PrimNumber{ public void getPrimnumber(int n){ int sum=0,i,j;for(i=1;i<=n;i++){ for(j=2;j<=i/2;j++){ if(i%j==0)break;}if(j>i/2)System.out.print(" "+i);}}public static void main(String args[]){ PrimNumber p=new PrimNumber();p.getPrimnumber(20);}}例子10import java.applet.Applet;import java.awt.*;public class Example4_10 extends Applet{ Button redbutton;public void init(){ redbutton=new Button("我是一个红色的按钮");redbutton.setBackground(Color.red);redbutton.setForeground(Color.white);add(redbutton);}}例子11import tom.jiafei.*; //引入包tom.jiafei中的类public class Example4_11{ public static void main(String args[]){ PrimNumber num=new PrimNumber();//用包tom.jiafei中的类创建对象num.getPrimnumber(30);}}例子12public class Example4_12{ public static void main(String args[]){ PrimNumber num=new PrimNumber();//要保证PrimNuber类和Example4_12类在同一目录中 num.getPrimnumber(120);}}Trangel.javapackage tom.jiafei;public class Trangle{ double sideA,sideB,sideC;boolean boo;public Trangle(double a,double b,double c){ sideA=a;sideB=b;sideC=c;if(a+b>c&&a+c>b&&c+b>a){ System.out.println("我是一个三角形");boo=true;}else{ System.out.println("我不是一个三角形");boo=false;}}public void 计算面积(){ if(boo){ double p=(sideA+sideB+sideC)/2.0;double area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC)) ;System.out.println("面积是:"+area);}else{ System.out.println("不是一个三角形,不能计算面积");}}public void 修改三边(double a,double b,double c){ sideA=a;sideB=b;sideC=c;if(a+b>c&&a+c>b&&c+b>a){ boo=true;}else{ boo=false;}}}例子13import tom.jiafei.Trangle;class Example4_13{ public static void main(String args[]){ Trangle trangle=new Trangle(12,3,1);trangle.计算面积();trangle.修改三边(3,4,5);trangle.计算面积();}}例子14class Example4_14{ private int money;Example4_14(){ money=2000;}private int getMoney(){ return money;}public static void main(String args[]){ Example4_14 exa=new Example4_14();exa.money=3000;int m=exa.getMoney();System.out.println("money="+m);}}例子15class Father{ private int money;float weight,height;String head;void speak(String s){ System.out.println(s);}}class Son extends Father{ String hand,foot;}public class Example4_15{ public static void main(String args[]){ Son boy;boy=new Son();boy.weight=1.80f;boy.height=120f;boy.head="一个头";boy.hand="两只手 ";boy.foot="两只脚";boy.speak("我是儿子");System.out.println(boy.hand+boy.foot+boy.head+boy.weight+boy.height);}}例子16class Chengji{ float f(float x,float y){ return x*y;}}class Xiangjia extends Chengji{ float f(float x,float y){ return x+y ;}}public class Example4_16{ public static void main(String args[]){ Xiangjia sum;sum=new Xiangjia();float c=sum.f(4,6);System.out.println(c);}}例子17class Area{ float f(float r ){ return 3.14159f*r*r;}float g(float x,float y){ return x+y;}}class Circle extends Area{ float f(float r){ return 3.14159f*2.0f*r;}}public class Example4_17{ public static void main(String args[]){ Circle yuan;yuan=new Circle();float length=yuan.f(5.0f);float sum=yuan.g(232.645f,418.567f);System.out.println(length);System.out.println(sum);}}例子18class A{final double PI=3.1415926;public double getArea(final double r){return PI*r*r;}}public class Example4_18{ public static void main(String args[]){ A a=new A();System.out.println("面积:"+a.getArea(100));}}例子19class 类人猿{ private int n=100;void crySpeak(String s){ System.out.println(s);}}class People extends 类人猿{ void computer(int a,int b){ int c=a*b;System.out.println(c);}void crySpeak(String s){ System.out.println("**"+s+"**");}}class Example4_19{ public static void main(String args[]){ 类人猿 monkey=new People();monkey.crySpeak("I love this game");People people=(People)monkey;puter(10,10);}}例子20class 动物{ void cry(){}}class 狗 extends 动物{ void cry(){ System.out.println("汪汪.....");}}class 猫 extends 动物{ void cry(){ System.out.println("喵喵.....");}}class Example4_20{ public static void main(String args[]){ 动物 dongwu;dongwu=new 狗();dongwu.cry();dongwu=new 猫();dongwu.cry();}}例子21abstract class A{ abstract int min(int x,int y);int max(int x,int y){ return x>y?x:y;}}class B extends A{ int min(int x,int y){ return x<y?x:y;}}public class Example4_21{ public static void main(String args[]){ A a;B b=new B();int max=b.max(12,34);int min=b.min(12,34);System.out.println("max="+max+" min="+min);a=b;max=a.max(12,34);System.out.println("max="+max);}}例子22abstract class 图形{ public abstract double 求面积();}class 梯形 extends 图形{ double a,b,h;梯形(double a,double b,double h){ this.a=a;this.b=b;this.h=h;}public double 求面积(){ return((1/2.0)*(a+b)*h);}}class 圆形 extends 图形{ double r;圆形(double r){ this.r=r;}public double 求面积(){ return(3.14*r*r);}}class 堆{ 图形底;double 高;堆(图形底,double 高){ this.底=底;this.高=高;}void 换底(图形底){ this.底=底;}public double 求体积(){ return (底.求面积()*高)/3.0;}}public class Example4_22{ public static void main(String args[]){ 堆 zui;图形 tuxing;tuxing=new 梯形(2.0,7.0,10.7);System.out.println("梯形的面积"+tuxing.求面积());zui=new 堆(tuxing,30);System.out.println("梯形底的堆的体积"+zui.求体积());tuxing=new 圆形(10);System.out.println("半径是10的圆的面积"+tuxing.求面积()); zui.换底(tuxing);System.out.println("圆形底的堆的体积"+zui.求体积());}}例子23class Student{ int number;String name;Student(){}Student(int number,String name){ this.number=number;=name;System.out.println("I am "+name+ "my number is "+number);}}class Univer_Student extends Student{ boolean 婚否;Univer_Student(int number,String name,boolean b){ super(number,name);婚否=b;System.out.println("婚否="+婚否);}}public class Example4_23{ public static void main(String args[]){ Univer_Student zhang=new Univer_Student(9901,"和晓林",false);}}例子24class Sum{ int n;float f(){ float sum=0;for(int i=1;i<=n;i++)sum=sum+i;return sum;}}class Average extends Sum{ int n;float f(){ float c;super.n=n;c=super.f();return c/n;}float g(){ float c;c=super.f();return c/2;}}public class Example4_24{ public static void main(String args[]){ Average aver=new Average();aver.n=100;float result_1=aver.f();float result_2=aver.g();System.out.println("result_1="+result_1);System.out.println("result_2="+result_2);}}例子25interface Computable{ int MAX=100;int f(int x);}class China implements Computable{ int number;public int f(int x) //不要忘记public关键字{ int sum=0;for(int i=1;i<=x;i++){ sum=sum+i;}return sum;}}class Japan implements Computable{ int number;public int f(int x){ return 44+x;}}public class Example4_25{ public static void main(String args[]){ China zhang;Japan henlu;zhang=new China();henlu=new Japan();zhang.number=991898+Computable.MAX;henlu.number=941448+Computable.MAX;System.out.println("number:"+zhang.number+"求和"+zhang.f(100));System.out.println("number:"+henlu.number+"求和"+henlu.f(100));}}例子26interface 收费{ public void 收取费用();}interface 调节温度{ public void controlTemperature();}class 公共汽车 implements 收费{ public void 收取费用(){ System.out.println("公共汽车:一元/张,不计算公里数");}}class 出租车 implements 收费, 调节温度{ public void 收取费用(){ System.out.println("出租车:1.60元/公里,起价3公里");}public void controlTemperature(){ System.out.println("安装了Hair空调");}}class 电影院 implements 收费,调节温度{ public void 收取费用(){ System.out.println("电影院:门票,十元/张");}public void controlTemperature(){ System.out.println("安装了中央空调");}}class Example4_26{ public static void main(String args[]){ 公共汽车七路=new 公共汽车();出租车天宇=new 出租车();电影院红星=new 电影院();七路.收取费用();天宇.收取费用();红星.收取费用();天宇.controlTemperature();红星.controlTemperature();}}例子27interface ShowMessage{ void 显示商标(String s);}class TV implements ShowMessage{ public void 显示商标(String s){ System.out.println(s);}}class PC implements ShowMessage{ public void 显示商标(String s){ System.out.println(s);}}public class Example4_27{ public static void main(String args[]){ ShowMessage sm;sm=new TV();sm.显示商标("长城牌电视机");sm=new PC();sm.显示商标("联想奔月5008PC机");}}例子28interface Computerable{ public double 求面积();}class 梯形 implements Computerable{ double a,b,h;梯形(double a,double b,double h){ this.a=a;this.b=b;this.h=h;}public double 求面积(){ return((1/2.0)*(a+b)*h);}}class 圆形 implements Computerable{ double r;圆形(double r){ this.r=r;}public double 求面积(){ return(3.14*r*r);}}class 堆{ Computerable 底;double 高;堆(Computerable 底,double 高){ this.底=底;this.高=高;}void 换底(Computerable 底){ this.底=底;}public double 求体积(){ return (底.求面积()*高)/3.0;}}public class Example4_28{ public static void main(String args[]){ 堆 zui;Computerable bottom;bottom=new 梯形(2.0,7.0,10.7);System.out.println("梯形的面积"+bottom.求面积());zui=new 堆(bottom,30);System.out.println("梯形底的堆的体积"+zui.求体积());bottom=new 圆形(10);System.out.println("半径是10的圆的面积"+bottom.求面积());zui.换底(bottom);System.out.println("圆形底的堆的体积"+zui.求体积());}}例子29interface SpeakHello{ void speakHello();}class Chinese implements SpeakHello{ public void speakHello(){ System.out.println("中国人习惯问候语:你好,吃饭了吗? ");}}class English implements SpeakHello{ public void speakHello(){ System.out.println("英国人习惯问候语:你好,天气不错 ");}}class KindHello{ public void lookHello(SpeakHello hello){ hello.speakHello();}}public class Example4_29{ public static void main(String args[]){ KindHello kindHello=new KindHello();kindHello.lookHello(new Chinese());kindHello.lookHello(new English());}}例子30class China{ final String nationalAnthem="义勇军进行曲";Beijing beijing;China(){ beijing=new Beijing();}String getSong(){ return nationalAnthem;}class Beijing{ String name="北京";void speak(){ System.out.println("我们是"+name+" 我们的国歌是:"+getSong()); }}}public class Example4_30{ public static void main(String args[]){ China china=new China();china.beijing.speak();}}例子31class Cubic{ double getCubic(int n){ return 0;}}abstract class Sqrt{ public abstract double getSqrt(int x);}class A{ void f(Cubic cubic){ double result=cubic.getCubic(3);System.out.println(result);}}public class Example4_31{ public static void main(String args[]){ A a=new A();a.f(new Cubic(){ double getCubic(int n){ return n*n*n;}});Sqrt ss=new Sqrt(){ public double getSqrt(int x) { return Math.sqrt(x);}};double m=ss.getSqrt(5);System.out.println(m);}}例子32interface Cubic{ double getCubic(int n);}interface Sqrt{ public double getSqrt(int x);}class A{ void f(Cubic cubic){ double result=cubic.getCubic(3);System.out.println(result);}}public class Example4_32{ public static void main(String args[]){ A a=new A();a.f(new Cubic(){ public double getCubic(int n){ return n*n*n;}});Sqrt ss=new Sqrt(){ public double getSqrt(int x){ return Math.sqrt(x);}};double m=ss.getSqrt(5);System.out.println(m);}}例子33public class Example4_33{ public static void main(String args[ ]){ int n=0,m=0,t=555;try{ m=Integer.parseInt("8888");n=Integer.parseInt("abc789");t=9999;}catch(NumberFormatException e){ System.out.println("发生异常:"+e.getMessage());e.printStackTrace();n=123;}System.out.println("n="+n+",m="+m+",t="+t);}}例子34class NopositiveException extends Exception{ String message;NopositiveException(int m,int n){ message="数字"+m+"或"+n+"不是正整数";}public String toString(){ return message;}}class Computer{ public int getMaxCommonDivisor(int m,int n) throws NopositiveException { if(n<=0||m<=0){ NopositiveException exception=new NopositiveException(m,n);throw exception;}if(m<n){ int temp=0;temp=m;m=n;n=temp;}int r=m%n;while(r!=0){ m=n;n=r;r=m%n;}return n;}}public class Example4_34{ public static void main(String args[]){ int m=24,n=36,result=0;Computer a=new Computer();try { result=a.getMaxCommonDivisor(m,n);System.out.println(m+"和"+n+"的最大公约数 "+result);m=-12;n=22;result=a.getMaxCommonDivisor(m,n);System.out.println(m+"和"+n+"的最大公约数 "+result);}catch(NopositiveException e){ System.out.println(e.toString());}}}例子35import ng.reflect.*;class Rect{ double width,height,area;public double getArea(){ area=height*width;return area;}}public class Example4_35{ public static void main(String args[]){ Rect rect=new Rect();Class cs=rect.getClass();String className=cs.getName();Constructor[] con=cs.getDeclaredConstructors();Field[] field=cs.getDeclaredFields() ;Method[] method=cs.getDeclaredMethods();System.out.println("类的名字:"+className);System.out.println("类中有如下的成员变量:");for(int i=0;i<field.length;i++){ System.out.println(field[i].toString());}System.out.println("类中有如下的方法:");for(int i=0;i<method.length;i++){ System.out.println(method[i].toString());}System.out.println("类中有如下的构造方法:");for(int i=0;i<con.length;i++){ System.out.println(con[i].toString());}}}例子36class Rect{ double width,height,area;public double getArea(){ area=height*width;return area;}}public class Example4_36{ public static void main(String args[]){ try{ Class cs=Class.forName("Rect");Rect rect=(Rect)cs.newInstance();rect.width=100;rect.height=200;System.out.println("rect的面积"+rect.getArea());}catch(Exception e){}}}例子37public class Example4_37{ public static void main(String args[ ]){ char a[]={'a','b','c','D','E','F'};for(int i=0;i<a.length;i++){ if(Character.isLowerCase(a[i])){ a[i]=Character.toUpperCase(a[i]);}else if(Character.isUpperCase(a[i])){ a[i]=Character.toLowerCase(a[i]);}}for(int i=0;i<a.length;i++){ System.out.print(" "+a[i]);}}}Mymoon.mfManifest-Version: 1.0Main-Class: ACreated-By: 1.4(Sun Microsystems Inc.)Test1.javapublic class Test1{ public void fTest1(){ System.out.println("I am a method In Test1 class");}}Test2.javapublic class Test2{ public void fTest2(){ System.out.println("I am a method In Test2 class");}}moon.mfManifest-Version: 1.0Class: Test1 Test2Created-By: 1.4(Sun Microsystems Inc.)第五章字符串例子1class Example5_1{ public static void main(String args[]){ String s1,s2;s1=new String("we are students");s2=new String("we are students");System.out.println(s1.equals(s2));System.out.println(s1==s2);String s3,s4;s3="how are you";s4="how are you";System.out.println(s3.equals(s4));System.out.println(s3==s4);}}例子2class Example5_2{ public static void main(String args[]){ int number=0;String s="student;entropy;engage,english,client";for(int k=0;k<s.length();k++){ if(s.regionMatches(k,"en",0,2)){ number++;}}System.out.println("number="+number);}}例子3class Example5_3{ public static void main(String args[]){ String a[]={"door","apple","Applet","girl","boy"};for(int i=0;i<a.length-1;i++){ for(int j=i+1;j<a.length;j++)。