50道javase练习题题库_第1页
50道javase练习题题库_第2页
50道javase练习题题库_第3页
50道javase练习题题库_第4页
50道javase练习题题库_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

50道javase练习题(50道javase练习题)

[program1]

Title:classicalquestion:thereareapairofrabbits,born

fromthirdmonthsafterbirtheachmonthapairofrabbits,

smallrabbitsgrowuptothirdmonthslater,everymonthand

apairofrabbits,iftherabbitdoesnotdie,

Whatisthetotalnumberofrabbitspermonth?

1.programanalysis:thenumberofrabbits.

1,1,2,3,5,8,13,21...

[program2]

Topic:determinethenumberofprimesbetween101-200,andthe

outputofallprimenumbers.

1.programanalysis:themethodofjudgingprimenumbers:

remove2tosqrt(anumber)withanumber,ifdivisible,

Itindicatesthatthisnumberisnotprime,andisaprime

number.

[program3]

Title:printoutallthe"Narcissusnumbers”,socalled

“narcissusnumber“referstoathreedigitnumber,thenumber

ofcubicandequaltothenumberitself.Forexample,"153"is

a"narcissusnumber””,

Becausethreetimesthreetimesthreetimes5+3153=1.

1.programanalysis:usetheforcycletocontrol100-999

numbers,eachnumberdecomposesabit,tenbits,hundreds.

[program4]

Title:apositiveintegerdecompositionofthequalityfactor.

Forexample:enter90,printout90=2*3*3*5.

Programanalysis:todecomposetheprimefactorofN,weshould

firstfindaminimumprimenumberk,andthencompletethe

followingsteps:

(1)iftheprimenumberisequaltoN,theprocessofdecomposing

theprimefactorisfinishedandprintedout.

(2)ifn<>k,butnisdivisiblebyK,thevalueofKshould

beprinted,anddividedbyNK,apositiveintegerasanewn

yourepeatthefirststep.

(3)ifnisnotdivisiblebyK,withk+1asthevalueofK,repeat

thefirststep.

[program5]

Title:usethenestingofconditionaloperatorstocomplete

thisquestion:studentswithacademicscores>=90pointsare

representedbyA,60-89pointsarerepresentedbyB,and60

pointsarerepresentedbyC.

1.programanalysis:(a>b)a:b?Thisisabasicexampleofthe

conditionaloperator.

[program6]

EntertwopositiveintegersmandN,findthegreatestcommon

divisorandleastcommonmultiple.

1.programanalysis:usingrollingmethod.

[program7]

Title:enteralineofcharacters,respectively,thenumberof

Englishletters,spaces,numbersandothercharacters.

1.programanalysis:usingthewhilestatement,fortheinput

characterisnot'\n.

[program8]

Topic:s=a+aa+aaa+aaaa+aa...A,whereaisanumber.For

example,2+22+222+2222+22222(thetotalsumof5numbers),a

fewnumberswithkeyboardcontrol.

1.programanalysis:thekeyistocalculateeachitemvalue.

[program9]

Topic:ifanumberisexactlyequaltothesumofitsfactors,

thisnumberiscalled"endofafew”.Forexample6=123.

programmingtofindallcompletedwithin1000.

[program10]

Topic:aballfromafreefallheightof100meters,eachlanding

halfantijumpbacktotheoriginalheight;thenfall,forit

inthetenthfloor,howmanymeters?Howhighistherebound

forthetenthtime?

[program11]

Title:1,2,3,4numbers,howmanydifferentnumberscanbe

formedwithouteachotherandthreedigits?Howmucharethey?

1.programanalysis:canfillat100,ten,anumberis1,2,

3,4.Thenremovethearrangementdoesnotmeetthecondition

whichallarranged.

[program12]

Title:corporatebonusesbasedonprofits.Profit(I)lessthan

orequalto10millionyuan,thebonuscanbe10%;profithigher

than10million,lessthan20million,lessthan10millionpart

ofthe10%Commission,higherthan10million,cocoapercentage

between20millionto7.5%;40million,20millionhigherthan

theparttheCommission,5%;40millionhigherthanthepart

between40millionto60million,totheCommissionof3%;

between60millionto100million,higherthan60million,to

theCommissionof1.5%,higherthan100million,

Morethan1millionyuanpartoftheCommissionby1%,fromthe

keyboardinputmonthprofitI,thetotalamountofbonusshould

beawarded?

1.programanalysis:pleaseuseafewaxestoboundaries,

positioning.Notethatthedefinitionneedstodefineinteger

growthbonus.

[program13]

Title:aninteger,plus100,isaperfectsquarenumber,plus

168isacompletesquarenumber,whatisthenumber?

1.programanalysis:judgmentinlessthan100thousand,the

numberofthefirstand100aftertheroot,thenthenumberof

plus268afterprescribing,ifafterprescribingresultsmeet

thefollowingconditions,whichistheresultof.Pleasesee

theconcreteanalysis:

[program14]

Enteracertainperiodofaday,judgmentdayisthefirstfew

daysthisyear?

1.programanalysis:inMarch5th,forexample,shouldfirst

addupthefirsttwomonths,andthenadd5days,thatis,the

firstfewdaysoftheyear,specialcircumstances,leapyear

andinputmonthisgreaterthan3,needtoconsidermorethan

oneday.

[program15]

Enterthreeintegersx,y,Z,pleaseputthethreenumberof

smalltolargeoutput.

1.programanalysis:wetrytogetthesmallestnumberonX,

thefirstXcomparedwiththeY,ifx>ywillXandYvalues

ofexchange,andthenxandZarecompared,ifx>ZwillXand

Zvaluesofexchange,sothattheminimumX.

[program16]

Topic:theoutputof9*9formulas.

1.programanalysis:branchesandareconsideredatotalof9

rows9,Icontrolline,Jcontrol.

[program17]

Themonkeyeatsthepeachproblem:themonkeytakesoffseveral

peachesonthefirstday,eatshalfimmediately,isnotaddicted,

eatsonemoresecond,inthemorning,willeatthepeach

remaininghalf,haseatenonemore.Aftereverymorningtoeat

therestofthedaybeforeaYibanlingyi.Thetenthdayinthe

morningtoeat,seeonlyapeach.Howmuchdidyoupickupfor

thefirstday?.

1.programanalysis:adoptthemethodofreversethinking,

forwardinferencefrom.

[program18]

Title:twotabletennisteamcompetition,eachpersonthree.

Ateamofa,B,Cthree,BteamsfortheX,y,Zthree.Thelist

ofmatcheshasbeendrawn.Someoneaskstheplayersforalist

ofthematches.Asaidheisnotmorethanx,Csaidhedidnot

x,Z,programmedtoidentifyalistofthreeteamsracing.

1.programanalysis:judgetheprimenumbermethod:useanumber

toremove2tosqrt(thisnumber),ifcanbedivisible,itshows

thatthisnumberisnotprime,andviceversaisprimenumber.

[program19]

Title:printthefollowingpattern(diamond)

*

***

Tiananmen

Result

Tiananmen

***

*

1.programanalysis:first,thegraphicsaredividedintotwo

partstosee,thefirstfourlinesofarule,thelatterthree

linesofarule,theuseofdoubleforcycle,thefirstlayer

controlline,thesecondlayercontrolcolumn.

[program20]

Thereisasequenceoffractions:2/1,3/2,5/3,8/5,13/8,

21/13...Andthesumofthefirst20oftheseries.

1.programanalysis:pleaseseizethechangerulebetweenthe

numerator.

[program21]

Title:1+2!+3!+...+20!

1.programanalysis:thisprocedureistobringthecumulative

becomeamultiplicative.

[program22]

Topic:usingrecursivemethodtofind5!.

1.programanalysis:recursiveformula:fn=fn1*4!

[program23]

Topic:thereare5peoplesittogether,askthefifthperson

howold?Hesaidhewas2yearsolderthanfourth.Askfourth

peopleage,hesaidthatmorethanthirdpeoplein2years.Ask

thirdpeople,morethansecondpeopleandtwo.Asksecondpeople,

twoyearsolderthanthefirstpersonsaid.Finallyaskedthe

firstman,hesaid,10yearsold.Howbigarefifthpeople?

1.programanalysis:usingtherecursivemethod,recursiveand

recursivebacksteppingisdividedintotwostages.Ifyouwant

toknowtheageoffifthpeople,youneedtoknowtheageof

thefourthperson,andinturn,pushtothefirstperson(10

yearsold),andthenpushback.

[program24]

Title:giveanomorethan5positiveintegers,requirements:

first,askitisafewdigits,two,reverseprintoutyour

figures.

[program25]

Title:a5digit,itisnotapalindromejudgment.That12321

isapalindrome,abitandbitthesametenmillion,with

thousandsofthesame.

[program26]

Title:enterthefirstletteroftheweektodeterminewhatday

itis.Ifthefirstletteristhesame,thencontinuetojudge

thesecondletter.

1.programanalysis:usingthesituationstatementisbetter,

ifthefirstletteristhesame,thenjudgetousethesituation

statementorifsentencetodeterminethesecondletters.

[program27]

Title:seekingprimeswithin100

[program28]

Title:sorting10numbers

1.programanalysis:canusetheselectionmethod,from9months

afterthecomparisonprocess,selectaminimumexchangewith

thefirstelement,thenextanalogy,withsecondelementsand

8Comparisonandexchange.

[program29]

Topic:finda3*3matrixanddiagonalelements

1.programanalysis:usedoubleforcyclecontrolinput

two-dimensionalarray,andthenaccumulatea[i][i]output.

[program30]

Topic:asortedarray.Nowenteranumber,accordingtothe

requirementsoftheoriginallawitisinsertedintothearray.

1.programanalysis:firstdeterminewhetherthenumberis

greaterthanthelastnumber,andthenconsidertheinsertion

ofthenumberofthemiddle,afterinsertingtheelementafter

thenumber,followedbyaposition.

[program31]

Title:outputanarrayinreverseorder.

1.programanalysis:thefirstandthelastexchange.

[program32]

Topic:takeanintegerafromtherightendofthebeginning

ofthe4~7.

Programanalysis:thiscanbeconsidered:

(1)moveato4bitfirst.

(2)tosetupalowof4for1,therestofthenumber0.Available

~(~0<<4)

(3)carryontheabovetwooperations.

[program33]

Title:printYangHuitriangle(printout10linesasshown

below)

1.programanalysis:

One

11

121

1331

14641

15101051

[program34]

Topic:enterthenumber3A,B,C,accordingtothesequence

ofoutput.

1.programanalysis:usingpointermethod.

[program35]

Theinputarray,thelargestexchangewiththefirstelement,

thesmallestwiththelastelementexchange,outputarray.

[program36]

Title:therearenintegers,sothatthenumberofthefront

ofthemovebacktomposition,andfinallymnumberintothe

frontofthenumberofM

[program37]

Topic:npersonalcircle,orderarranging.Startedfromthe

firstreport(from1to3report),whoreported3peopleout

ofthecircle,leavingthelastquestionistheoriginalnumber.

[program38]

Title:writeafunction,findthelengthofastring,enterthe

stringinthemainfunction,andoutputitslength.

[program39]

Title:writeafunction,inputnevennumber,callthefunction

for1/2+1/4+...+l/n,whentheinputnisodd,callthefunction

1/1+1/3+...+l/n(usingpointerfunction)

[program40]

Stringsorting.

[program41]

Thebeachthereisapileofpeaches,fivemonkeysto.Thefirst

monkeydividedthepeachesintofiveparts,onemore.Themonkey

threwoneofthemanyintotheseaandtookone.

Thesecondmonkeysdividedtheremainingpeachesintofive

equally,andanotherone,whichthrewonemoreintothesea,

tookone,andthird,fourth,andfifthmonkeysdidthesame,

Asktheoriginalonthebeachatleasthowmanypeaches?

[program42]

Topic:809*??=800*??+9*??+1??thetwodigit,

8*??theresultistwodigits,9*??theresultis3digits.Ask

for??thedoubledigits,andtheresultof809*??.

[program43]

Topic:fortheoddnumberof0to7can.

[program44]

Topic:anevennumbercanalwaysbeexpressedasthesumoftwo

primes.

[program45]

Topic:whetheraprimenumbercanbedivisibleby9

[program46]

Title:twostringconnectionprogram

[program47]

Title:readtheintegernumberof7numbers(1-50),reada

valueeverytime,andprintoutthenumberofthevalue.

[program48]

Topic:usingapublictelephonetransmissionofdata,thedata

isfourintegers,inthetransmissionprocessisencrypted,

encryptionrulesareasfollows:Eachfigureswith5,andthen

dividedby10toreplacetheremainderofthedigital,thefirst

andfourthexchange,secondandthirdexchange.

[program49]

Topic:Calculationofstringneutron

[program50]

Topic:therearefivestudents,eachstudenthas3classesof

results,morethanfromthekeyboardinputdata(including

studentnumber,name,threecourseresults),calculatethe

averagescore,thestatusoftheoriginaldataandcalculated

theaveragescoreisstoredinthediskfile"stud".

SomeofthemareClanguagequestions,buttheyshouldbedone

withJAVA

1.codingtoachievetheinheritanceofelectricalrelations:

[useJavadocannotationclass,allmethods,]1electrical

appliancesclass(Wiring)hasattributes:power(power),rated

voltage(pressure),

Ratedcurrent(current)andDCtype(electricity).Method:

defaultconstructionmethod(initializationvoltagevalueis

220V,ACandDCtypeis"AC"),

Theelectricalmethod(work),thepreparationofgetandset

method1TVforeachattribute(TV)attribute:TVtype(type),

themaximumvolume(volume)methodhas:constructionmethod

(currentworkingvoltage100V,50TV,TVtypeinitialization

rainbow50inchLCD,maximumvolume,200)TVworkmethod(work)

[TVoutputal1theattributesintheworkofthevalue,write

getandsetLfortheTVrefrigeratorCategoryattribute(Icebox)

attribute:Volume(capacity)methodwithvoltagemethod

[achieveinitializationrefrigerator110V,current53,

capacityofworkingmethods230.5]refrigerator(work)

[attribute],refrigeratorgetpreparedwithsetmethodthe

valueofoutputallattributesintheworkoftherefrigerator;

Throughinheritancetoachievetheaboverequirements,and

preparethetestclassWiringTesttest.

2.encodingisrealizedusingEmployeeandProgra

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论