资源描述:
《50道javase练习题(50道javase练习题)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、50道javase练习题(50道javase练习题)[program1]Title:classicalquestion:thereareapairofrabbits,bornfromthirdmonthsafterbirtheachmonthapairofrabbits,smallrabbitsgrowuptothirdmonthslater,everymonthandapairofrabbits,iftherabbitdoesnotdie,Whatisthetotalnumberofrabbitspermonth?1.programanalysis:thenumb
2、erofrabbits・1,1,2,3,5,&13,21…[program2]Topic:determinethenumberofprimesbetween101-200,andtheoutputofallprimenumbers・1.programanalysis:themethodofjudgingprimenumbers:remove2tosqrt(anumber)withanumber,ifdivisible,Itindicatesthatthisnumberisnotprime,andisaprimenumber・[program3]Title:print
3、outallthe"Narcissusnumbers",socalled''narcissusnumber"referstoathreedigitnumber,thenumberofcubicandequaltothenumberitself.Forexample,"153〃isanarcissusnumber,Becausethreetimesthreetimesthreetimes5+3153=1.1.programanalysis:usetheforcycletocontrol100-999numbers,eachnumberdecomposesabit,te
4、nbits,hundreds・[program4]Title:apositiveintegerdecompositionofthequalityfactor・Forexample:enter90,printout90=2*3*3*5・Programanalysis:todecomposetheprimefactorofN,weshouldfirstfindaminimumprimenumberk,andthencompletethefollowingsteps:(1)iftheprimenumberisequaltoN,theprocessofdecomposing
5、theprimefactorisfinishedandprintedout.(2)ifn<>k,butnisdivisiblebyK,thevalueofKshouldbeprinted,anddividedbyNK,apositiveintegerasanewnyourepeatthefirststep・(3)ifnisnotdivisiblebyK,withk+1asthevalueofK,repeatthefirststep・[program5]Title:usethenestingofconditionaloperatorstocompletethisque
6、stion:studentswithacademicscores>=90pointsarerepresentedbyA,60-89pointsarerepresentedbyB,and60pointsarerepresentedbyC・1.programanalysis:(a>b)a:b?Thisisabasicexampleoftheconditionaloperator・[program6]EntertwopositiveintegersmandN,findthegreatestcommondivisorandleastcommonmultiple・1.prog
7、ramanalysis:usingrollingmethod・[program7]Title:enteralineofcharacters,respectively,thenumberofEnglishletters,spaces,numbetsandothercharacters・1.programanalysis:usingthewhilestatement,fortheinputcharacterisnot,.[program8]Topic:s=a+aa+aaa+aaaa+aa・・・A,whereaisanumber・Forexample,2+22+2