欢迎来到天天文库
浏览记录
ID:42615213
大小:32.00 KB
页数:7页
时间:2019-09-18
《java经典例题2》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Éè¼ÆÒ»¸ö¾ØÐÎÀ࣬¼ÆËãijһ¸ø¶¨¾ØÐεÄÃæ»ýpublicclasshRli{publicstaticvoidmain(String[]args){hRlir1=newhRli(5.4,5.8);System.out.println("r1µÄÃæ»ý"+r1.computerArea());}}classhRli{doublewidth;doubleheight;hRli(doubleW,doubleH){width=W;height=H;}publicdoublecomputerA
2、rea(){returnheight*width;}}±à³Ì¼ÆËã´Ó10µ½20µÄƽ·½Öµ£¬²¢½«½á¹û±£´æÔÚÒ»¸öÊý×éÖС£publicclassert{intr[];publicvoidcalc(inti,intj){intk=0;inttemp=0;intitemp=i;for(;itemp<=j;temp++){itemp++;}r=newint[temp];temp=0;for(;i<=j;i++,k++){r[k]=i*i;temp++;}//testfor(k=0;k<
3、temp;k++){System.out.println(r[k]);}}publicstaticvoidmain(String[]args){ertert=newSq();ert.calc(10,20);}}ÉèÓмÆËã½×³ËµÄº¯Êýf(n)=n!£¬ÊÔÉè¼ÆÒ»¸ö¼ÆËã½×³ËµÄ·½·¨ºÍÏàÓ¦µÄÀ࣬²¢ÀûÓÃÕâ¸öÀà¼ÆËãf(5)ºÍf(17)µÄÖµ¡£publicclassret{publicinti;publiclongf(inti){inttemp=i;longr
4、esult=1;for(;temp>0;temp--){result=result*temp;}returnresult;}publicstaticvoidmain(String[]args){retf1=newFactorial();System.out.println("5µÄ½×³Ë:"+f1.f(5));System.out.println("17µÄ½×³Ë:"+f1.f(17));}}2.±àдһ¸ö×Ö·û½çÃæµÄJavaApplication³ÌÐò£¬½ÓÊÜÓû§ÊäÈëµÄ10¸öÕ
5、ûÊý£¬²¢Êä³öÕâ10¸öÕûÊýµÄ×î´óÖµºÍ×îСֵimportjava.io.*;importjava.lang.*;importjava.util.StringTokenizer;classret{publicstaticvoidmain(Stringargs[]){StringTokenizerst=newStringTokenizer("10203040");Strings="";int[]b=newint[10];intMax=0,Min=0;intcount=0;System.ou
6、t.println("ÊäÈë10¸öÊý×ÖÓÿոñ¸ô¿ªÀýÈç:110314557670182950");try{BufferedReaderin=newBufferedReader(newInputStreamReader(System.in));s=in.readLine();st=newStringTokenizer(s);}catch(Exceptione){System.out.print(e.getMessage());}while(st.hasMoreTokens()){b[count]=
7、Integer.parseInt(st.nextToken());count++;}Min=b[0];for(inti=0;ib[i]){Min=b[i];}}System.out.println("Max:"+Max);System.out.println("Min:"+Min);}}3.ÔĶÁÏÂÁгÌÐò£¬Ð´³öÔËÐнá¹û£ºpublicclassExam3_4{publicstaticvoidma
8、in(String[]args){Strings,s1="";charc;s=¡°wELCOME¡±;for(inti=0;i='a'&&c<='z'){s1=s1+Character.toUpperCase(c);}else{s1=s1+Character.toLowerCase(c)
此文档下载收益归作者所有