一道Java的題目 求編程
一道Java的題目 求編程
Problem Description:
Write a program that reads integers,findsthe largest of them,and counts its occurrences.Assume that the input endswith number 0.Suppose that you entered 3 5 2 5 5 5 0; the program finds thatthe largest is 5 and the occurrence count for 5 is 4.(Hint:Maintain twovariables,max and count.max stores the current max number,and count storesits occurrences.Initially,assign the first number to max and 1 to count.Compare each subsequent number with max.If the number is greater than max,assign it to max and reset count to 1.If the number is equal to max,incrementcount by 1.)
Here are sample runs of the program:
Sample 1:
Enternumbers:3 5 2 5 5 5 0
Thelargest number is 5
Theoccurrence count of the largest number is 4
Sample 2:
Enternumbers:3 6 5 4 2 4 5 4 55 0
Thelargest number is 6
Theoccurrence count of the largest number is 1
Problem Description:
Write a program that reads integers,findsthe largest of them,and counts its occurrences.Assume that the input endswith number 0.Suppose that you entered 3 5 2 5 5 5 0; the program finds thatthe largest is 5 and the occurrence count for 5 is 4.(Hint:Maintain twovariables,max and count.max stores the current max number,and count storesits occurrences.Initially,assign the first number to max and 1 to count.Compare each subsequent number with max.If the number is greater than max,assign it to max and reset count to 1.If the number is equal to max,incrementcount by 1.)
Here are sample runs of the program:
Sample 1:
Enternumbers:3 5 2 5 5 5 0
Thelargest number is 5
Theoccurrence count of the largest number is 4
Sample 2:
Enternumbers:3 6 5 4 2 4 5 4 55 0
Thelargest number is 6
Theoccurrence count of the largest number is 1
其他人氣:156 ℃時(shí)間:2020-06-29 20:57:10
優(yōu)質(zhì)解答
首先你讀懂題沒(méi)有,我?guī)湍惴g一下:?jiǎn)栴}描述: 編寫(xiě)一個(gè)程序,讀取整數(shù),找出其中最大的,并計(jì)算其出現(xiàn)次數(shù).假設(shè)輸入與數(shù)字0結(jié)束.假設(shè)你進(jìn)入3 5 2 5 5 5 0;程序發(fā)現(xiàn),最大的為5,出現(xiàn)次數(shù)為4. (提示:建立兩個(gè)變量,...
我來(lái)回答
類似推薦
- 關(guān)于萬(wàn)有引力定律的發(fā)現(xiàn),正確的是 A牛頓通過(guò)望遠(yuǎn)鏡觀察天體運(yùn)動(dòng)發(fā)現(xiàn)的 B牛頓通過(guò)探究蘋(píng)果落地發(fā)現(xiàn)的
- 為什么紅細(xì)胞可攜帶二氧化碳
- I know I'm really in love with you..I care and I really don't want to lose you
- 0.8L=()dm3=()cm3
- 有沒(méi)有I like winter的作文?急用 .求你了!幫個(gè)忙!(>_
- 一臺(tái)電動(dòng)機(jī)正常工作時(shí),兩端的電壓為220V,通過(guò)線圈的電流為10A,若此線圈的電阻為2Ω,那么它的電功率是_W,這臺(tái)電動(dòng)機(jī)1min內(nèi)產(chǎn)生的熱量是_J,這臺(tái)電動(dòng)機(jī)的效率是_.(最后一空保留三位
- forget現(xiàn)分及形容詞 cook形容詞,名詞兩個(gè)
- 如圖,△ABC為等邊三角形,且BM=CN,AM與BN相交于點(diǎn)P,則∠APN=_.
- 一項(xiàng)工程甲乙合作12天可以完成.途中甲停工5天,因此用了15天完成.甲獨(dú)做這項(xiàng)工程要用幾天?
- 描寫(xiě)夏天梔子花清香的句子
- 設(shè)有連續(xù)函數(shù)f,k(x)=積分(0->1)f(t*x)dt,且f(x)/x=A,求k'(x)
- They got much _____(infoemation)from those new books .
猜你喜歡
- 1家用電器或線路著火,可用泡沫滅火器撲救是對(duì)的還是錯(cuò)的?
- 2Shall we have some chicken wings?(同義句轉(zhuǎn)換)
- 3子彈在水平飛行時(shí),其動(dòng)能為Ek0=800J,某時(shí)它炸裂成質(zhì)量相等的兩塊,其中一塊的動(dòng)能為Ek1=625J,求另一塊的動(dòng)能Ek2.
- 4甲乙丙三個(gè)同學(xué)參加儲(chǔ)蓄,甲存款是乙的4/5,丙存款比乙少40%,已知甲存了500元,丙存了多少元?
- 5函數(shù)f(x)=sin(πx/2-π/4)的圖象是由函數(shù)y=sinx的圖象經(jīng)過(guò)怎樣的變換得到的?
- 6歷史題選擇題【詳細(xì)解析區(qū)分一下】THANK YOU
- 7英語(yǔ)單詞的過(guò)去式和反義詞
- 8設(shè)A是m*n矩陣,B是n*m矩陣.證明當(dāng)M>n時(shí),必有|AB|=0
- 9a*b=a (a小于等于b) =b (a大于b)如果1*2=1,則函數(shù)2^x*2^(-x)的值域
- 10The twins____members of the school football team A are both B both are
- 11最小正周期和周期有什么區(qū)別?
- 125551用加減乘除,括號(hào)怎樣等于24