您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 求职简历 > Java实用教程第二版常用语句
importjava.applet.*;importjava.awt.*;publicclassBoyextendsApplet{publicvoidpaint(Graphicsg){g.setColor(Color.red);g.drawString(我一边喝着咖啡,一边学Java呢,5,30);g.setColor(Color.blue);g.drawString(我学得很认真,10,50);}}publicclassEx3{publicstaticvoidmain(Stringargs[]){longsum=1,temp=1;for(inti=2;i=10;i++){temp=temp*i;sum=sum+temp;}System.out.println(1!+2!+...+10!=+sum);}}publicclassEx4{publicstaticvoidmain(Stringargs[]){inti=1;intj;while(i=1000){i++;for(j=2;ji;j++)if(i%j==0)break;if(i==j)System.out.println(i+是素数);}}}publicclassEx6{publicstaticvoidmain(Stringargs[]){intsum;for(inti=2;i=1000;i++){sum=0;for(intj=1;ji;j++){if(i%j==0){sum=sum+j;}}if(sum==i){System.out.println(i+是完数);}}}}publicclassEx8{publicstaticvoidmain(Stringargs[]){inta=2,b=3,c=7;intd=ac?a:c;d=d2b?d:b;System.out.println(b);}}publicclassHello{publicstaticvoidmain(Stringargs[]){System.out.println(你好,很高兴学习Java);}}importjava.lang.*;classTrangle{doublea,b,c,p;booleans;Trangle(doublea,doubleb,doublec){this.a=a;this.b=b;this.c=c;}publicdouble周长(){returna+b+c;}publicdouble求面积(){p=(a+c+b)/2;returnMath.sqrt(p*(p-a)*(p-b)*(p-c));}voidjudgeTrangle(){if((a+b)c&&(a+c)b&&(b+c)a)s=true;elses=false;}}classLeder{doubleub,db,h;Leder(doubleub,doubledb,doubleh){this.ub=ub;this.db=db;this.h=h;}double面积(){return((ub+db)*h)/2;}}classCircle{doubler;doublepi=3.1415926;Circle(doubler){this.r=r;}double求周长(){return2*r*pi;}doublearea(){returnr*r*pi;}}publicclassExample{publicstaticvoidmain(Stringargs[]){Tranglesanjiao;Ledertixing;Circleyuan;sanjiao=newTrangle(3.0,4.0,5.0);System.out.println(三角形的周长:+sanjiao.周长());System.out.println(三角形的面积:+sanjiao.求面积());tixing=newLeder(2.0,4.0,1.0);System.out.println(梯形的面积:+tixing.面积());yuan=newCircle(3.0);System.out.println(圆的周长:+yuan.求周长());System.out.println(圆的面积:+yuan.area());}}classCompany{Employee[]employee;doublesalaries=0;Company(Employee[]employee){this.employee=employee;}publicdoublesalariesPay(){salaries=0;for(inti=0;iemployee.length;i++){if(YearWorker.class.isInstance(employee[i]))salaries+=employee[i].earnings();if(MonthWorker.class.isInstance(employee[i]))salaries+=employee[i].earnings()*12;if(WeekWorker.class.isInstance(employee[i]))salaries+=employee[i].earnings()*52;}//计算salaries。returnsalaries;}}abstractclassEmployee{publicabstractdoubleearnings();//声明一个公有的抽象方法earnings,方法返回类型为double}publicclassHardWork{publicstaticvoidmain(Stringargs[]){Employee[]employee=newEmployee[20];for(inti=0;iemployee.length;i++){if(i%3==0)employee[i]=newWeekWorker();elseif(i%3==1)employee[i]=newMonthWorker();elseif(i%3==2)employee[i]=newYearWorker();}Companycompany=newCompany(employee);System.out.println(公司年工资总额:+company.salariesPay());}}classMonthWorkerextendsEmployee{publicdoubleearnings(){return8000;}//重写earnings()方法。}classWeekWorkerextendsEmployee{publicdoubleearnings(){return1000;}//重写earnings()方法。}classYearWorkerextendsEmployee{publicdoubleearnings(){return120000;}//重写earnings()方法}classPeople{protecteddoubleweight,height;publicvoidspeakHello(){System.out.println(yayawawa);}publicvoidaverageHeight(){height=173;System.out.println(averageheight:+height);}publicvoidaverageWeight(){weight=70;System.out.println(averageweight:+weight);}}classAmericanPeopleextendsPeople{publicvoidspeakHello(){System.out.println(Howdoyoudo?);}//重写publicvoidspeakHello()方法,要求输出类似//“Howdoyoudo”这样的英语信息。publicvoidaverageHeight(){System.out.println(美国人的平均身高:170厘米);}//重写publicvoidaverageHeight()方法publicvoidaverageWeight(){System.out.println(美国人的平均体重:70公斤);}//重写publicvoidaverageWeight()方法publicvoidamericanBoxing(){System.out.println(直拳、勾拳···);//输出拳击的信息,例如,“直拳”、“钩拳”等}}classBeijingPeopleextendsChinaPeople{publicvoidspeakHello(){System.out.println(您好);}//重写publicvoidspeakHello()方法,要求输出类似“您好”这样的汉语信息publicvoidaverageHeight(){System.out.println(北京人的平均身高:165厘米);}//重写publicvoidaverageHeight()方法publicvoidaverageWeight(){System.out.println(北京人的平均体重:60公斤);}//重写publicvoidaverageWeight()方法publicvoidbeijingOpera(){System.out.println(脸谱、国粹);//输出京剧的信息}}classChinaPeopleextendsPeople{publicvoidspeakHello(){System.out.println(你好,吃了吗?);}//重写publicvoidspeakHello()方法,要求输出类似“你好,吃了吗”这样的//汉语信息publicvoidaverageHeight(){System.out.println(中国人的平均身高:168.78厘米);}//重写publicvoidaverageHeight()方法,要求输出类似//“中国人的平均身高:168.78厘米”这样的汉语信息publicvoidaverageWeight(){System.out.println(中国人的平均体重:65公斤);}//重写publicvoidaverageWeight()方法,//要求输出类似“中国人的平均体重:65公斤”这样的汉语信息publicvoidchinaGongfu(){System.out.println(坐如钟,站如松,睡如弓);//输出中国武术的信息,例如:坐如钟,站如松,睡如弓等}}publicclassExample{publicstaticvoidmain(Stringargs[]){ChinaPeoplechinaPeople=newChinaPeople();AmericanPeopleamericanPeople=newAmericanPeople();BeijingPeoplebeijingPeople=newBeijingPeople();chinaPeople.speakHello();americanPeople.speakHello();beijingPeople.speakHello();chinaPeople.averageHeight();americanPeople.averageHeight();beijingPeople.averageHeight();chinaPeople.averageWeight();americanPeople.averageWeight();beijingPeople.averageWeight();chinaPeople.chinaGongfu();americanPeople.americanBoxing();beijingPeople.beijingOpera();beijingPeople.chinaGongfu();}}classA{floata;//声明一个fl
本文标题:Java实用教程第二版常用语句
链接地址:https://www.777doc.com/doc-2878642 .html