




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
java练习题目(java练习题目)
[program1]
Title:classicalquestion:thereareapairofrabbits,from
birththirdmonthsfromthebirthofapairofrabbitsevery
month,thelittlerabbitgrowstothirdmonths,amonthafter
birth
Forrabbits,ifrabbitsdon'tdie,askthetotalnumberof
rabbitspermonth?
1.programanalysis:thelawsoftherabbitseries
1,1,2,3,5,8,13,21
[program2]
Title:determinehowmanyprimestherearebetween101-200,and
outputallprimes.
1.programanalysis:determinetheprimenumbermethod:with
anumberof2tosqrtremoved(thisnumber),ifyoucanbe
divisible,
Itshowsthatthisnumberisnotaprimenumber,butisaprime
number.
[program3]
Title:printoutallthe“narcissusnumber”,theso-called
“narcissusnumber"referstoathreedigit,thenumberofcubic
andequaltothenumberitself.Suchas:
The153isa“daffodils”,becausethreetimesthreetimesthree
times5+3153=1.
1.programanalysis:theuseofforcyclecontrol100-999
numbers,eachdecompositionofanumberofbits,ten,100.
[program4]
Title:factoringapositiveintegerintoaprimefactor.For
example:enter90andprintout90=2*3*3*5.
Programanalysis:whenfactoringtheN,weshouldfirstfind
aminimumprimenumber,K,andthencompletethefollowing
steps:
(1)iftheprimenumberisexactlyn,theprocessoffactoring
thequalityfactorisoverandprintedout.
(2)ifnOk,butncanbedivisiblebyK,youshouldprintout
thevalueofK,andusentodividethequotientofKasthe
newpositiveinteger,youn,repeatthefirststep.
(3)ifncannotbedivisiblebyK,usek+1asthevalueofK
andrepeatthefirststep.
[program5]
Title:usethenestingofconditionaloperatorstocomplete
thisquestion:studentswithgrades>=90arerepresentedbyA,
between60-89pointsbyB,below60points
RepresentedbyC.
1.programanalysis:(a>b)a:b,whichisabasicexampleofthe
conditionaloperator.
[program6]
EntertwopositiveintegersmandN,findthegreatestcommon
divisorandleastcommonmultiple.
1.programanalysis:theuseofrolling.
[program7]
Title:enteralineofcharacters,respectively,statisticsin
whichEnglishletters,spaces,numbersandothercharactersof
thenumber.
1.programanalysis:usewhilestatement,theconditionforthe
inputcharacterisnot''n'.
[program8]
Title:s=a+aa+aaa+aaaa+aa=avalue,inwhichaisanumber.
Forexample,2+22+222+2222+22222(thereare5numbersadded
together),
Severalnumbersareaddedwithkeyboardcontrol.
1.programanalysis:thekeyistocalculatethevalueofeach
item.
[program9]
Topic:ifanumberisexactlyequaltothesumofitsfactors,
thisnumberiscalled“endofafew”.Forexample6=123.
programmingtofindallfinishedwithin1000
Thenumberof.
[program10]
Topic:abal1fromafreefallheightof100meters,eachlanding
halfantijumpbacktotheoriginalheight;thenfall,forit
inthetenthfloor,atotalofover
Lessrice?Howhighisthetenthbounce?
[program11]
Title:1,2,3,4numbers,howmanydifferentnumberscanbe
formedwithouteachotherandthreedigits?Howmucharethey?
1.,programanalysis:canfillinonehundred,ten,anumber
ofdigitsare1,2,3,4.Makeupallpermutationsandthen
removepermutationsthatdonotmeettherequirements.
[program12]
Title:bonusespaidbyenterprisesarebasedonprofits.When
theprofit(I)isbeloworequalto100thousandyuan,thebonus
canberaisedby10%;theprofitishigherthan100thousand
yuan,lessthan200thousand
Yuan,lessthan100thousandyuaninpart,accordingto10%
Commission,higherthan100thousandyuanpart,cocoa
Commission7.5%;200thousandto400thousandbetween,higher
than200thousandyuanDepartment
Cent,candeductapercentagefrom5%;between400thousandand
600thousandwhenthepartishigherthan400thousandyuan,
candeductapercentagefrom3%;between600thousandand1
millionwhen,thepartthatishigherthan600thousandyuan
can
Deductapercentagefrom1.5%,whenhigherthan1millionyuan,
morethan1millionyuanpart,press1%deductapercentagefrom
asumofmoney,
Enterthemonthprofitfromthekeyboard,I,andaskforthe
bonus
1.programanalysis:pleaseuseafewaxestoboundaries,
positioning.Whendefiningthedefinition,youneedtodefine
thebonusasagrowthinteger.
[program13]
Title:aninteger,plus100,isaperfectsquare,plus168is
aperfectsquarenumber.What'sthenumber?
1.programanalysis:judgmentinlessthan100thousand,the
numberofthefirstand100aftertheroot,thenthenumberof
plus268afterprescribing,ifafterprescribingresultsmeet
Thefollowingconditions,thatistheresult.Pleaseseethe
concreteanalysis:
[program14]
Topic:enterayear,amonth,adate,todeterminethedayis
thefirstfewdaysoftheyear?
1.programanalysis:inMarch5th,forexample,thefirsttwo
monthsshouldbeaddedup,andthenplus5days,thatis,the
firstfewdaysoftheyear,specialcircumstances,leapyear,
and
Youneedtoconsideraddingonemoredaytothemonthwhenthe
inputisgreaterthan3.
[program15]
Enterthreeintegersx,y,Z,pleaseputthethreenumberof
smalltolargeoutput.
1.programanalysis:wewouldliketoputthesmallestnumber
ontheX,comparexwithyfirst,ifx>ywillexchangethevalue
ofXandy,andthenuseX
ComparewithZ,ifx>zwillexchangethevalueofXandZ,this
canmakexminimum.
[program16]
Topic:theoutputof9*9formulas.
1.programanalysis:branchandcolumnconsidered,atotalof
91ines,9columns,Icontrol1ine,Jcontrolcolumn.
[program17]
Question:monkeyseatpeachesproblem:monkeyspickedoffafew
peachesonthefirstday,immediatelyatehalf,notaddicted,
andeatasecondday,themorningwillbeleft
Thepeachatehalf,andateonemore.Everymorning,Iatethe
daybefore
TheYibanlingyia.Bythetenthmorning,whenIwantedtoeat
again,Isawonlyonepeachleft.Askforthefirstday.
1.programanalysis:reversethinking,fromthebacktoinfer.
[program18]
Title:twotabletennisteamsplay,eachwiththreeplayers.
Ateamisa,B,Cthree,teamBisx,y,Zthree.Thelistof
matcheshasbeendrawnup.Someoneto
Theteaminquiredaboutthelistofmatches.Asayshedoesn't
comparewithX,andCsayshedoesn,tcomparewithX,Z,and
askstheprogramtofindalistofthethreeteamplayers.
1.programanalysis:determinetheprimenumbermethod:with
anumberofremovalof2tosqrt(thisnumber),ifyoucanbe
divisible,itshowsthatthisnumberisnotprime,inverse
Primenumber.
[program19]
Title:printthefollowingpattern(diamond)
*
***
Tiananmen
Result
Tiananmen
***
*
1.programanalysis:first,thegraphicsaredividedintotwo
partstolookat,thefirstfourlinesofarule,thelatter
threelinesofarule,theuseofdoubleforcycle,thefirst
layerofcontrol
OK,secondlayercontrolcolumn.
[program20]
Title:thereisasequenceoffractions:2/1,3/2,5/3,8/5,
13/8,21/13...Andthesumofthefirst20oftheseries.
1.programanalysis:pleaseseizethelawofchangeofnumerator
anddenominator.
[program21]
Title:1+2,+3,...+...+20...And...
1.programanalysis:Thisprogramjustaccumulatedintoatired
ride.
[program22]
Title:usingrecursivemethodfor5!.
1.programanalysis:recursiveformula:fn=fn1*4!
[program23]
Title:5peoplesittogetherandaskhowoldarefifthpeople?
Hesaidhewas2yearsolderthanfourth.Askedtheageoffourth,
hesaidhewas2yearsolderthanthird,ask
Thirdpeople,secondyearsolderthantwo.Askedsecondpeople,
saidtwoyearsolderthanthefirstperson.Finallyaskedthe
firstman,hesaid,is10yearsold.Fifth,please
Howoldareyou?
1.programanalysis:theuseofrecursivemethod,recursive
dividedintobackpushandrecursivetwostages.Ifyouwant
toknowtheageoffifth,youmustknowtheageofthefour,
Byanalogy,pushtothefirstperson(10yearsold),thenpush
back.
[program24]
Title:toanomorethan5positiveintegers,requirements:
first,askitisafewdigits,two,thereverseprintoutyour
figures.
[program25]
Title:a5digitnumbertodeterminewhetheritispalindrome.
Thatis,12321isthepalindromenumber,thebitisthesame
asthetens,andthetenbitisthesameasthethousand.
[program26]
Title:Pleaseenterthefirstletteroftheweektodetermine
whatdayitis.Ifthefirstletteristhesame,thencontinue
tojudgethesecondletters.
1.programanalysis:itisbettertousethecasestatement.
Ifthefirstletteristhesame,thenjudgethesecondletters
withthecasestatementortheifstatement.
[program27]
Title:seektheprimenumberwithin100
[program28]
Title:sort10numbers
1.programanalysis:youcanusetheselectionmethod,thatis,
fromthelatter9comparisonprocess,selectaminimumandthe
firstelementoftheexchange,andthenextanalogy,thatis,
withthefirst
Thetwoelementsarecomparedwiththelatter8andexchanged.
[program29]
Title:thesumofthediagonalelementsofa3*3matrix
1.programanalysis:theuseofdoubleforloopcontrolinput
two-dimensionalarray,andthena[i][i]cumulativeoutput.
[program30]
Title:thereisanarrayalreadyingoodorder.Nowentera
number,theoriginallawrequiredtoinsertitintothearray.
1.programanalysis:firstdeterminewhetherthisnumberis
greaterthanthelastnumber,andthenconsidertheinsertion
ofthemiddlenumber,afterinsertingtheelementafterthe
number,
Moveonepositionbackwardinturn.
[program31]
Title:outputanarrayinreverseorder.
1.programanalysis:usethefirstoneandthelastone.
[program32]
Title:takeanintegera,startingfromtherightsideofthe
4〜7bit.
Programanalysis:thiscanbeconsidered:
(1)firstmoveato4bits.
(2)setalow4bit,all1,andtheremaining0.Available
C0«4)
(3)performtheoperationsofthetwoabove.
[program33]
Title:printouttheYangHuitriangle(asktoprintout10lines,
asshownbelow)
1.programanalysis:
One
11
121
1331
14641
15101051
[program34]
Title:enter3numbersa,B,C,outputinsizeorder.
1.programanalysis:usingpointermethod.
[program35]
Title:enterthearray,thelargestwiththefirstelementof
theexchange,thesmallestwiththelastelementoftheexchange,
outputarray.
[program36]
Title:therearenintegers,sothatthefrontofthenumber
ofmovingbackwardmposition,andfinallythenumberofM
becomesthenumberofminthefront
[program37]
Topic:npersonalcircle,orderarranging.Startedfromthe
firstreport(from1to3report),whoreported3peopleout
ofthecircle,askthelasttoleave
Whowastheoriginalnumber?.
[program38]
Title:writeafunctiontofindthelengthofastring,enter
thestringinthemainfunction,andoutputitslength.
[program39]
Title:writeafunction,enterthenisevennumbers,callthe
functionfor1/2+1/4+...+l/n,whentheinputnisodd,call
thefunction
1/1+1/3+...+l/n(usingpointerfunction)
[program40]
Title:stringsorting.
[program41]
Topic:thereisapileofpeachesonthebeach,andfivemonkeys
aredivided.Thefirstmonkeydividedthepileofpeachesinto
fiveparts,onemore,andthemonkeyputmorethanone
Onethrewintotheseaandtookone.Thesecondmonkeysdivided
theremainingpeachesintofiveequally,andonemore,andit
threwonemoreintothesea
Takeone,third,fourth,fifthmonkeysdothat,andaskhowmany
peachesarethereonthebeachatleast
[program42]
Title:809*?=800*?+9*?+1?
Amongthem,therepresentativeofthetwodigit,8*,andthe
resultistwodigit,9*,andtheresultis3figures.Beg?
Representtwodigits,
And809*?Aftertheresults.
[program43]
Title:anoddnumberthatcanbecomposedof0-7.
[program44]
Title:anevennumbercanalwaysbeexpressedasthesumoftwo
primenumbers.
[program45]
Title:aprimenumbercanbedividedbyafew9
[program46]
Title:twostringconnectionprogram
[program47]
Title:readthewholenumberof7numbers(1-50),eachread
avalue,theprogramprintoutthevalueofthenumberof*.
[program48]
Title:acompanyusesapublictelephonetotransmitdata.The
dataisanintegeroffourbits.Itisencryptedduringthe
transmission.Theencryptionrulesareasfollows:eachdigit
Bothadd5,thendividethenumberbyandby10insteadofthe
number,thenexchangethefirstbitandthefourthbit,the
secondbitandthethirdbit.
[program49]
Title:howmanytimesdoesstringstringappear?
[program50]
Title:therearefivestudents,eachstudenthas3classesof
results,fromthekeyboardinputoftheabovedata(including
studentnumber,name,threeclassresults),calculated
Averageresults,originaldata,andcalculatedaveragescores
arestoredinthediskfile"stud".
1.Writeadatecalculationprogram.Designrequirements:
(choosetomakeone)
1)amonthisenteredbytheuser,andthemonthcalendaris
displayedonthescreeneveryMonday,andendsfromSundayto
Saturday.
2)enteradatebytheuserandthescreenansweriswhatday
oftheweek.
3)entertwodatesbytheuserandcalculatethedifference
betweenthetwodates.
2,enterastring,statisticsinwhichthenumberofcharacters
appear.
3.Enter3integersfromthekeyboard,andcalculatewhether
thetrianglewiththe3numbersisrighttriangle.
4,inApplettoachievethecalculatorfunction:youcan+,-
*,/fourarithmetic.
1,defineacircleclassthatincludesthemethodofcalculating
theareaofthecircleandthecircumferenceofthecircle.If
theradiusoftheinputislessthan0,acustomexceptionis
thrown.
2.Writeadivisionprogramthatrequiresthedivisorandthe
divisortobeenteredfromthekeyboard.Iftheinputdivisor
isanonnumerictypesuchas6y,theprogramautomatically
interruptsandthrowstheNumberFormatExceptionexception
withoutenteringthedivisorprogram.Iftheinputdivisoris
0,theprogramthrowstheArithmeticExceptionexception.And
usefinallytoprocessthefinalresult.
3,adesignfromthecommandline(keyboard)inputastring
program,ifthestringvalueis"123"exceptionisan
Exceptionl23(custom),anddisplaythe“123stringcausedby
abnormal
1,programmingtocreateaBoxclass,definethreevariables
acubeoflength,widthandheightinthem,andthendefinea
methodsetDemotoinitializethethreevariables,andthen
defineamethodtocalculatethevolumeofacube.Createan
objecttofindthesizeofacubeofagivensize.
2,thetitleofthemethod,setDemoconstructortoachieve
initialization.
3,programmingtocreateaPointclass,definetwovariables
ofcoordinatesofapointvalueinthem,andthendefinea
constructorinitializationastheoriginofcoordinates,and
thendefineamethodtorealizethepointmove,thendefinea
coordinatepointofthecurrentprintmethod.Andcreatean
objectverification.
4,defineaclassthatimplementstheconceptofbankaccounts,
includingvariablessuchasaccountsandbalances.Methods
includedeposits,withdrawals,andquerybalances”.Definethe
mainclass,createtheobjectoftheaccountclass,andcomplete
theappropriateoperation.
5,thedefinitionofthefollowingbasicclasses,requiresthe
realizationofinheritance:point,Cylinder,Circle,class,
cylinder,inheritancepoint,cylinder,inheritancecircle.The
circleradius,thecircleareaandthecylindervolumecanbe
calculated.
6,defineamedia(media)classthatcontainsinformationsuch
asname,author,publisher,andprice,andcanenterthis
informationfromthekeyboard.
Thencreatemediasubclasses:books(Book)andcd.
ProgrammingFibonaccisequence.TheFibonacciseriesis
definedas:
Fl=l,F2=l...
Fn=Fn-l+Fn-2(n>=3)
Tip:thekeycodeisasfollows:
F[0]=f[l]=l;
For(i=2;i<10;i++)
2.,buildanumericarray,calculatetheoddnumbersandall
theoddvalues,and.
3.usingthearraytoachievethebasicfunctionsofthequeue:
Aqueueisabasicdatastructurethatfollowstheprinciple
offirstin,firstout.Thequeueusuallysupportstwobasic
operations:put,get(to)(made),eachputoperationwillbe
anewelementinthequeuetail;eachgetoperationwillbea
newelementtogetthenextelementinthequeueatthebeginning.
Queueelementsareexpendable,andonceanelementhasbeen
obtained,itcannotbeacquiredagain.Ifthequeuehasnospace,
itisfull.Iftherearenoelementsinthequeue,thecolumn
isempty.
4.whatarethedisadvantagesofusingarrays?
(1)usingsimpleifstatementprogramming,typethreeintegers
fromthekeyboard,andthenoutputtheminorderfromsmallto
large.
(2)useif-else-ifstatementsandswitchstatementsto
determinewhichseasonamonthis,respectively.
(3)programmingenterthegradesofstudents,academic
achievements,andgivethecorrespondingachievementrange.
Setalevelof85ormore(including85points);Bclassis70
pointsormore(including70points);Cclassismorethan60
points(including60points);Dclassisbelow60points.Using
theifstatementandtheswitchstatement,respectively.
(4)usingthecontinuestatement:outputthenumbersbetween
100〜300thatcannotbedivisibleby3.
(5)usethebreakstatementtoachievethecount:from1〜100,
whenyoucountto78,theprogramterminates.
(6)usewhile,DO-WHILEandforstatementprogramming
respectively,seekthesumof「100.
(7)usewhile,DO-WHILEandforstatementprogramming
respectively,findoutallnarcissusnumberandoutput.The
numberofdaffodilsisthreedigits,andthecubeofitsnumbers
isequaltothethreedigititself,forexample:
371=33+73+13371isanarcissusnumber.
(8)anintegerisenteredbytheuser,andtheresultisgiven
bytheprogramtodeterminewhetheritisaprimenumberornot.
Orenterarangebytheuser,theprogramlistsalltheprime
numberswithinthatrange
(9)printthefollowingdiagramusingcyclicstatements:
*
***
Miss
xl>
ZTXZTSXTHZivXTS
Thisiswhenourteachergavethetitle,verysystematic,for
youtostudymustbeofgreathelp
sixsi*sixxlxxlxxtxxl*xlxxfxxlzxl*xl*xlxxlxxlxxlxxlzxtxxlxxlxxlxxlxxlxxfxvl*xlxxtxsixxlxxJxxlz*1*xlxxlzxtx*X*xlxxlzxl*xlxxlzxlx
ZTSZTXXjXXTSXT**T*XTXXT**TS✓JXXTX*T*XTSXT**T*XTXXTX**1>XTSZTX^7^*TSXTXXTXXTXXISZTSXTXX7S**1>XT>XTXXTXXTXZjXZTS*TS
x|cx|c
1,respectively,writeApplicationandAppletprogram,display
string"HelloJava”!Welcometouse!”.
2,printyourownnamewith'.Suchas"King"isprintedas
xl*vtxxJxxlxxlxKL*xlzxL*
•THXTS*7*>TXXTSXTXXTX
**
**
x|cx|c
**
**
sL*X,L*sixvl*xlxxl>xtxxlxxlxxlxxJx
xp»*T**T*XTXXTSXT**T**T»XTXZT*
*1**1**£**1**1*xfz*1*xl*xlxsixxl*vt*xl**lz*1^xl*^1**fxsi**lz*lzxl*xlzxl*xl*si**1*xlzxlz*1*xlzxfx*1*si**1**lz*lx*1**X*xlz*X*xlz«Xz
q、*TXXT*(、*7xxTxXTXq、"、XT%XTX/、*TX*T%XT%XTX*TV*T%*TX*7*XT**Tx*T%XTX*TVXTX*T*
*1**1**1**A**lx*lzsi*xt**1**1**1**lz*lx*Ix%lxxlz%I*KIXvlx*X**XZ*1*xl*
ZT%*TX*T*ZT**TX*TX*TXZTX/、ZT**TX*T**TX*TX*TXZTX
1,usingtheBufferedReaderclassfromthekeyboardtoreceive
anintegerandarealnumber,calculatetheirsum,andthen
outputonthescreen.
Tip:thekeysentencesareasfollows:
BufferedReaderDIN=newBufferedReader(new,
InputStreamReader(System,in));
I=Integer.parselnt(din.readLine());
F=Float.parseFloat(din.readLine());
2,throughtheinterfaceinputtwointegers,thegreatest
c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 茶叶品牌授权与加盟合作合同
- 城市绿线测绘与城市管理合同范本
- 铲车销售与租赁、维修、保养、培训合同范本
- 网络安全领域公司成立出资协议书
- 成都市房产中介服务与二手房交易合同
- 被迫解除劳动合同关系通知书
- 中职学校书法活动方案
- 学校学生浴室管理制度
- 卫生卫生制度管理制度
- 单位文件传阅管理制度
- 安全环保专业试题库
- 机房动力系统综合实训知到智慧树章节测试课后答案2024年秋四川邮电职业技术学院
- 山地户外运动基地建设项目可行性研究报告
- 2025年国航股份地面服务部校园招聘笔试参考题库含答案解析
- 污水处理设备安装维护与改造安全生产培训
- DG-TJ 08-2336-2020 绿道建设技术标准
- 宣传物料制作合同范本
- 分心驾驶培训课件
- (高清版)DB52∕T 1041-2015 贵州省红粘土和高液限土路基设计与施工技术规范
- 国开《铸牢中华民族共同体意识》形考任务1-3
- 电厂灰库结构工程施工方案
评论
0/150
提交评论